graph/education: slightly improve error handling and logging

- Use var for common errors
- Add the addition error message to the Error() output of errorcode.Error
- in PatchEducationSchool() use errorcode.RenderError() to turn the errorcode
  in to the right HTTP Status (instead of return 500 always)
This commit is contained in:
Ralf Haferkamp
2023-09-27 15:39:00 +02:00
committed by Ralf Haferkamp
parent 4f59de9c52
commit a34d467285
8 changed files with 42 additions and 69 deletions
@@ -148,7 +148,7 @@ func (g Graph) PatchEducationSchool(w http.ResponseWriter, r *http.Request) {
if school, err = g.identityEducationBackend.UpdateEducationSchool(r.Context(), schoolID, *school); err != nil {
logger.Debug().Err(err).Interface("school", school).Msg("could not update school: backend error")
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, err.Error())
errorcode.RenderError(w, r, err)
return
}
@@ -130,7 +130,11 @@ func (e ErrorCode) String() string {
}
func (e Error) Error() string {
return errorCodes[e.errorCode]
errString := errorCodes[e.errorCode]
if e.msg != "" {
errString += ": " + e.msg
}
return errString
}
// RenderError render the Graph Error based on a code or default one