feat: 404 on ErrNoRows, 500 on err != nil

This commit is contained in:
DarkCat09 2024-07-02 19:13:22 +04:00
parent 459d10664a
commit bc6490187d
Signed by: DarkCat09
GPG key ID: 0A26CD5B3345D6E3

View file

@ -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