feat: custom http error in json format
This commit is contained in:
17
internal/web/error.go
Normal file
17
internal/web/error.go
Normal file
@ -0,0 +1,17 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func Error(w http.ResponseWriter, err string, code int) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.Header().Set("X-Content-Type-Options", "nosniff")
|
||||
w.WriteHeader(code)
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{
|
||||
"error": err,
|
||||
"status": code,
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user