ripple-api/app/error_handler.go

28 lines
631 B
Go
Raw Normal View History

2016-04-07 09:38:57 +00:00
package app
import (
2016-05-22 15:11:07 +00:00
"fmt"
"git.zxq.co/ripple/schiavolib"
2016-04-07 09:38:57 +00:00
"github.com/fatih/color"
"github.com/gin-gonic/gin"
)
// ErrorHandler is a middleware for gin that takes care of calls to c.Error().
func ErrorHandler() gin.HandlerFunc {
return func(c *gin.Context) {
c.Next()
errs := c.Errors.Errors()
if len(errs) != 0 {
color.Red("!!! ERRORS OCCURRED !!!")
2016-05-22 15:11:07 +00:00
var out string
out += fmt.Sprintf("==> %s %s\n", c.Request.Method, c.Request.URL.Path)
2016-04-07 09:38:57 +00:00
for _, err := range errs {
2016-05-22 15:11:07 +00:00
out += fmt.Sprintf("===> %s\n", err)
2016-04-07 09:38:57 +00:00
}
2016-05-22 15:11:07 +00:00
color.Red(out)
2016-05-28 18:28:13 +00:00
go schiavo.Bunker.Send("Errors occurred:\n```\n" + out + "```")
2016-04-07 09:38:57 +00:00
}
}
}