mirror of
https://github.com/Pungyeon/clean-go-article.git
synced 2024-11-10 01:14:04 +00:00
improve error handling
This commit is contained in:
parent
8da89bdc0a
commit
d94be4024a
|
@ -698,7 +698,7 @@ By simply representing the error as a variable (`ErrItemNotFound`), we've ensure
|
||||||
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 == clean.ErrItemNotFound {
|
if errors.Is(err, clean.ErrItemNotFound) {
|
||||||
http.Error(w, err.Error(), http.StatusNotFound)
|
http.Error(w, err.Error(), http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue