/
foult080
/
hackaton-app
Обзор
Документация
Войти
/
foult080
/
hackaton-app
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
pkg/apperror/apperror.go
54 строки
1 KB
Foult080
refactor(): migrate to golang
07 июл 2026, 09:37
07 июл 2026, 09:37
dc52ff5
Код
Авторство
О чём код?
package apperror import ( "fmt" ) type AppError struct { Message string `json:"message"` StatusCode int `json:"statusCode"` Details []string `json:"details,omitempty"` } func New(message string, statusCode int) *AppError { return &AppError{Message: message, StatusCode: statusCode} } func NewWithDetails(message string, statusCode int, details []string) *AppError { return &AppError{Message: message, StatusCode: statusCode, Details: details} } func (e *AppError) Error() string { if len(e.Details) > 0 { return fmt.Sprintf("%s: %v", e.Message, e.Details) } return e.Message } func BadRequest(message string) *AppError { return New(message, 400) } func Unauthorized(message string) *AppError { return New(message, 401) } func Forbidden(message string) *AppError { return New(message, 403) } func NotFound(message string) *AppError { return New(message, 404) } func Conflict(message string) *AppError { return New(message, 409) } func TooManyRequests(message string) *AppError { return New(message, 429) } func InternalServer(message string) *AppError { return New(message, 500) }