Specify http not found exit code

by replacing it with StatusGone (410) for a missing runner and StatusFailedDependency (424) for missing or not accessible files.
This commit is contained in:
Maximilian Paß
2022-08-30 14:14:24 +02:00
parent fc77f11d4d
commit 3469d0ce77
8 changed files with 81 additions and 63 deletions

View File

@ -11,12 +11,8 @@ func writeInternalServerError(writer http.ResponseWriter, err error, errorCode d
sendJSON(writer, &dto.InternalServerError{Message: err.Error(), ErrorCode: errorCode}, http.StatusInternalServerError)
}
func writeBadRequest(writer http.ResponseWriter, err error) {
sendJSON(writer, &dto.ClientError{Message: err.Error()}, http.StatusBadRequest)
}
func writeNotFound(writer http.ResponseWriter, err error) {
sendJSON(writer, &dto.ClientError{Message: err.Error()}, http.StatusNotFound)
func writeClientError(writer http.ResponseWriter, err error, status uint16) {
sendJSON(writer, &dto.ClientError{Message: err.Error()}, int(status))
}
func sendJSON(writer http.ResponseWriter, content interface{}, httpStatusCode int) {
@ -36,7 +32,7 @@ func sendJSON(writer http.ResponseWriter, content interface{}, httpStatusCode in
func parseJSONRequestBody(writer http.ResponseWriter, request *http.Request, structure interface{}) error {
if err := json.NewDecoder(request.Body).Decode(structure); err != nil {
writeBadRequest(writer, err)
writeClientError(writer, err, http.StatusBadRequest)
return fmt.Errorf("error parsing JSON request body: %w", err)
}
return nil