improve error handling

This commit is contained in:
bitcodr 2020-08-07 12:19:28 +04:30
parent 0595e82363
commit 8da89bdc0a

View file

@ -794,7 +794,7 @@ And our HTTP handler function can then be refactored to check for a specific err
func GetItemHandler(w http.ReponseWriter, r http.Request) { func GetItemHandler(w http.ReponseWriter, r http.Request) {
item, err := clean.GetItem("123") item, err := clean.GetItem("123")
if err != nil { if err != nil {
if err.Type() == clean.ErrItemNotFound { if errors.Is(err.Type(), clean.ErrItemNotFound) {
http.Error(w, err.Error(), http.StatusNotFound) http.Error(w, err.Error(), http.StatusNotFound)
return return
} }