make graph/education API errors more consistent

This commit is contained in:
David Christofas
2023-02-28 15:25:45 +01:00
parent bdbd70d352
commit 0fadc79c32
5 changed files with 30 additions and 2 deletions

View File

@@ -100,9 +100,14 @@ func (e ErrorCode) Render(w http.ResponseWriter, r *http.Request, status int, ms
}
func (e Error) Render(w http.ResponseWriter, r *http.Request) {
status := http.StatusInternalServerError
if e.errorCode == ItemNotFound {
var status int
switch e.errorCode {
case ItemNotFound:
status = http.StatusNotFound
case NameAlreadyExists:
status = http.StatusConflict
default:
status = http.StatusInternalServerError
}
e.errorCode.Render(w, r, status, e.msg)
}