MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / MapErrorToHTTPStatus

Function MapErrorToHTTPStatus

internal/apierror/apierror.go:66–84  ·  view source on GitHub ↗

MapErrorToHTTPStatus maps APIError codes to appropriate HTTP status codes. It returns the corresponding HTTP status code for the given APIError.

(err error)

Source from the content-addressed store, hash-verified

64// MapErrorToHTTPStatus maps APIError codes to appropriate HTTP status codes.
65// It returns the corresponding HTTP status code for the given APIError.
66func MapErrorToHTTPStatus(err error) int {
67 if apiErr, ok := err.(APIError); ok {
68 switch apiErr.Code {
69 case ErrNotFound:
70 return http.StatusNotFound // HTTP 404 Not Found for missing resources.
71 case ErrConflict:
72 return http.StatusConflict // HTTP 409 Conflict for conflicting requests.
73 case ErrInvalidInput:
74 return http.StatusBadRequest // HTTP 400 Bad Request for invalid inputs.
75 case ErrInternalServer:
76 return http.StatusInternalServerError // HTTP 500 Internal Server Error for server issues.
77 case ErrRateLimited:
78 return http.StatusTooManyRequests // HTTP 429 Too Many Requests for rate limiting.
79 default:
80 return http.StatusInternalServerError
81 }
82 }
83 return http.StatusInternalServerError // Default to 500 Internal Server Error if no specific mapping is found.
84}

Callers 1

TestMapErrorToHTTPStatusFunction · 0.92

Calls

no outgoing calls

Tested by 1

TestMapErrorToHTTPStatusFunction · 0.74