feat: 에러 처리 표준화 + BossRaid 낙관적 잠금
에러 표준화: - pkg/apperror — AppError 타입, 7개 sentinel error - pkg/middleware/error_handler — Fiber ErrorHandler 통합 - 핸들러에서 AppError 반환 시 구조화된 JSON 자동 응답 BossRaid Race Condition: - 상태 전이 4곳 낙관적 잠금 (UPDATE WHERE status=?) - TransitionRoomStatus/TransitionRoomStatusMulti 메서드 추가 - ErrStatusConflict sentinel error Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
33
pkg/apperror/apperror.go
Normal file
33
pkg/apperror/apperror.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package apperror
|
||||
|
||||
import "fmt"
|
||||
|
||||
// AppError is a structured application error with an HTTP status code.
|
||||
type AppError struct {
|
||||
Code string `json:"error"`
|
||||
Message string `json:"message"`
|
||||
Status int `json:"-"`
|
||||
}
|
||||
|
||||
func (e *AppError) Error() string { return e.Message }
|
||||
|
||||
// New creates a new AppError.
|
||||
func New(code string, message string, status int) *AppError {
|
||||
return &AppError{Code: code, Message: message, Status: status}
|
||||
}
|
||||
|
||||
// Wrap creates a new AppError that wraps a cause error.
|
||||
func Wrap(code string, message string, status int, cause error) *AppError {
|
||||
return &AppError{Code: code, Message: fmt.Sprintf("%s: %v", message, cause), Status: status}
|
||||
}
|
||||
|
||||
// Common errors
|
||||
var (
|
||||
ErrUnauthorized = &AppError{Code: "unauthorized", Message: "인증이 필요합니다", Status: 401}
|
||||
ErrForbidden = &AppError{Code: "forbidden", Message: "권한이 없습니다", Status: 403}
|
||||
ErrNotFound = &AppError{Code: "not_found", Message: "리소스를 찾을 수 없습니다", Status: 404}
|
||||
ErrConflict = &AppError{Code: "conflict", Message: "이미 존재합니다", Status: 409}
|
||||
ErrBadRequest = &AppError{Code: "bad_request", Message: "잘못된 요청입니다", Status: 400}
|
||||
ErrInternal = &AppError{Code: "internal_error", Message: "서버 오류가 발생했습니다", Status: 500}
|
||||
ErrRateLimited = &AppError{Code: "rate_limited", Message: "요청이 너무 많습니다", Status: 429}
|
||||
)
|
||||
Reference in New Issue
Block a user