Compare commits

...

2 commits

Author SHA1 Message Date
27a8c3d1d1
fix: convert ctx.Method() []byte to string
see similar commit 10d174f626
2024-07-02 19:14:30 +04:00
bc6490187d
feat: 404 on ErrNoRows, 500 on err != nil 2024-07-02 19:13:22 +04:00

View file

@ -58,7 +58,7 @@ func handler(ctx *fasthttp.RequestCtx) {
)
row := stmt.QueryRow(
ctx.Method(),
string(ctx.Method()),
fmt.Sprintf(
"%s://%s:%s%s",
scheme,
@ -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