NewAPIError creates a new APIError instance. It logs the error details and returns the error object with the provided code, message, and additional details.
(code ErrorCode, message string, details interface{})
| 53 | // NewAPIError creates a new APIError instance. |
| 54 | // It logs the error details and returns the error object with the provided code, message, and additional details. |
| 55 | func NewAPIError(code ErrorCode, message string, details interface{}) APIError { |
| 56 | logrus.WithField("details", details).Error("API error") // Log the error details for monitoring and debugging. |
| 57 | return APIError{ |
| 58 | Code: code, |
| 59 | Message: message, |
| 60 | Details: details, |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | // MapErrorToHTTPStatus maps APIError codes to appropriate HTTP status codes. |
| 65 | // It returns the corresponding HTTP status code for the given APIError. |