diff --git a/app/error_handler.go b/app/error_handler.go deleted file mode 100644 index e1eb5c2..0000000 --- a/app/error_handler.go +++ /dev/null @@ -1,27 +0,0 @@ -package app - -import ( - "fmt" - - "git.zxq.co/ripple/schiavolib" - "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 !!!") - var out string - out += fmt.Sprintf("==> %s %s\n", c.Request.Method, c.Request.URL.Path) - for _, err := range errs { - out += fmt.Sprintf("===> %s\n", err) - } - color.Red(out) - go schiavo.Bunker.Send("Errors occurred:\n```\n" + out + "```") - } - } -} diff --git a/app/start.go b/app/start.go index 41c1864..d65ef38 100644 --- a/app/start.go +++ b/app/start.go @@ -2,12 +2,15 @@ package app import ( "database/sql" + "fmt" "git.zxq.co/ripple/rippleapi/app/internals" "git.zxq.co/ripple/rippleapi/app/peppy" "git.zxq.co/ripple/rippleapi/app/v1" "git.zxq.co/ripple/rippleapi/common" + "github.com/getsentry/raven-go" "github.com/gin-gonic/contrib/gzip" + "github.com/gin-gonic/contrib/sentry" "github.com/gin-gonic/gin" ) @@ -17,7 +20,16 @@ var db *sql.DB func Start(conf common.Conf, dbO *sql.DB) *gin.Engine { db = dbO r := gin.Default() - r.Use(gzip.Gzip(gzip.DefaultCompression), ErrorHandler()) + r.Use(gzip.Gzip(gzip.DefaultCompression)) + + if conf.SentryDSN != "" { + ravenClient, err := raven.New(conf.SentryDSN) + if err != nil { + fmt.Println(err) + } else { + r.Use(sentry.Recovery(ravenClient, false)) + } + } api := r.Group("/api") { @@ -80,6 +92,9 @@ func Start(conf common.Conf, dbO *sql.DB) *gin.Engine { } api.GET("/status", internals.Status) + api.GET("/errore_meme", func(c *gin.Context) { + c.Error(fmt.Errorf("This is a test error!")) + }) // peppyapi api.GET("/get_user", PeppyMethod(peppy.GetUser)) diff --git a/common/conf.go b/common/conf.go index 9f7d2fb..67d230a 100644 --- a/common/conf.go +++ b/common/conf.go @@ -13,6 +13,7 @@ type Conf struct { DSN string `description:"The Data Source Name for the database. More: https://github.com/go-sql-driver/mysql#dsn-data-source-name"` ListenTo string `description:"The IP/Port combination from which to take connections, e.g. :8080"` Unix bool `description:"Bool indicating whether ListenTo is a UNIX socket or an address."` + SentryDSN string `description:"thing for sentry whatever"` } var cachedConf *Conf