forked from mtusi2026/mtusi2026lab6
feat: add bounded observability and verified SLO incident alerts
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user