-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror_registry_entry.go
More file actions
27 lines (23 loc) · 1.07 KB
/
Copy patherror_registry_entry.go
File metadata and controls
27 lines (23 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package restapi
// ErrorRegistryEntry binds an application error code to the HTTP status code
// and human-readable message that should be returned when that error is raised.
//
// Entries are registered in an [ErrorRegistry] and looked up at response time
// by [API.Error], [API.Abort], and [API.NewError].
type ErrorRegistryEntry struct {
// StatusCode is the HTTP status code to return.
StatusCode int `json:"statusCode"`
// ErrorCode is the application error code that identifies the entry.
// It is distinct from StatusCode: many application codes may map to the
// same HTTP status.
ErrorCode int `json:"errorCode"`
// Message is the default human-readable message for the entry. Callers
// may override it per-response with [WithMessage].
Message string `json:"message"`
}
// Response returns a new [ErrorResponse] initialised with the entry's
// ErrorCode and Message. It is the canonical way to turn a registry entry
// into a response body component.
func (e ErrorRegistryEntry) Response() ErrorResponse {
return ErrorResponse{Code: e.ErrorCode, Message: e.Message}
}