Docs / ArchitectureKit / Guides / Mapping Errors to Status Codes

Mapping Errors to Status Codes

To get the status code that matches an error, call the StatusFor function:

status := httpapi.StatusFor(err)

It checks the categories in this order:

Error Status code
nil 200 OK
httpapi.ErrUnauthorized 401 Unauthorized
httpapi.ErrForbidden 403 Forbidden
httpapi.ErrTooLarge 413 Request Entity Too Large
httpapi.ErrUnsupportedMediaType 415 Unsupported Media Type
httpapi.ErrMalformed 400 Bad Request
httpapi.ErrNotFound, query.ErrNoItems 404 Not Found
architecturekit.ErrDomain 422 Unprocessable Entity
architecturekit.ErrConflict 409 Conflict
architecturekit.ErrTransient 503 Service Unavailable
any other error 500 Internal Server Error