feat: 404 on ErrNoRows, 500 on err != nil
This commit is contained in:
parent
459d10664a
commit
bc6490187d
1 changed files with 5 additions and 1 deletions
|
@ -72,9 +72,13 @@ func handler(ctx *fasthttp.RequestCtx) {
|
|||
var code int
|
||||
|
||||
err := row.Scan(&id, &code)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
ctx.Response.SetStatusCode(404)
|
||||
return
|
||||
} else if err != nil {
|
||||
ctx.Response.SetStatusCode(500)
|
||||
ctx.Response.SetBodyString("Unable to fetch row: " + err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// -- set status code
|
||||
|
|
Loading…
Reference in a new issue