forked from mtusi2026/mtusi2026lab3
34 lines
1.2 KiB
Go
34 lines
1.2 KiB
Go
package fiber
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"go.lab260.ru/fielderr"
|
|
)
|
|
|
|
// NewErrorRegistry returns an immutable mapping of application statuses to HTTP codes.
|
|
// The registry is injected rather than installed in process-global state, allowing
|
|
// independent application instances in integration tests.
|
|
func NewErrorRegistry() (*fielderr.Registry, error) {
|
|
return fielderr.NewRegistry(
|
|
statusDefinition(codeInvalid, http.StatusBadRequest),
|
|
statusDefinition(codeUnauthorized, http.StatusUnauthorized),
|
|
statusDefinition(codeNotFound, http.StatusNotFound),
|
|
statusDefinition(codeConflict, http.StatusConflict),
|
|
statusDefinition(codeTooLarge, http.StatusRequestEntityTooLarge),
|
|
statusDefinition(codeMedia, http.StatusUnsupportedMediaType),
|
|
statusDefinition(codeRateLimited, http.StatusTooManyRequests),
|
|
statusDefinition(codeUnavailable, http.StatusServiceUnavailable),
|
|
statusDefinition(codeInternal, http.StatusInternalServerError),
|
|
)
|
|
}
|
|
|
|
// statusDefinition associates an application error code with its HTTP status.
|
|
func statusDefinition(name string, httpStatus int) fielderr.StatusDefinition {
|
|
return fielderr.StatusDefinition{
|
|
Code: fielderr.NewStatusCode(name),
|
|
Name: name,
|
|
HTTPStatus: httpStatus,
|
|
}
|
|
}
|