Improve http error messages

This commit is contained in:
Tobie Morgan Hitchcock 2017-11-16 20:38:53 +00:00
parent fd3df8dbfc
commit 96cd07e1d1
2 changed files with 12 additions and 12 deletions

View file

@ -44,19 +44,24 @@ func errors(val error, c *fibre.Context) {
case *sql.ParseError:
code, info = 400, e.Error()
case *fibre.HTTPError:
code = e.Code()
code, info = e.Code(), e.Error()
}
if _, ok := errs[code]; !ok {
code = 500
}
c.Send(code, &err{
errs[code].Code,
errs[code].Details,
errs[code].Description,
info,
})
switch c.Type() {
case "text/plain":
c.Send(code, info)
default:
c.Send(code, &err{
errs[code].Code,
errs[code].Details,
errs[code].Description,
info,
})
}
}

View file

@ -24,7 +24,6 @@ import (
"github.com/abcum/surreal/sql"
"github.com/abcum/surreal/util/build"
"github.com/abcum/surreal/util/show"
"github.com/gorilla/websocket"
)
func limit(c *fibre.Context, i int64) int64 {
@ -175,9 +174,6 @@ func routes(s *fibre.Fibre) {
for {
_, msg, err := c.Socket().Read()
if err != nil {
if websocket.IsCloseError(err, 1000, 1001, 1005) {
return nil
}
return err
}
if res, err := db.Execute(c, msg, nil); err != nil {
@ -186,7 +182,6 @@ func routes(s *fibre.Fibre) {
c.Socket().SendJSON(res)
}
}
return nil
})
// --------------------------------------------------