Files
ProxyPilot/internal/errors/app_error.go
T
FinessseandClaude Opus 4.5 7b3ef0ea43 refactor(errors): remove unused error constructors
Removed 5 unused helper functions: BadRequest(), Unauthorized(),
Forbidden(), NotFound(), InternalServerError(). Also removed the
now-unused net/http import.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 02:50:05 +07:00

50 lines
1.1 KiB
Go

package errors
import (
"encoding/json"
"fmt"
)
// AppError represents a structured application error.
type AppError struct {
// HTTPStatusCode is the HTTP status code to return.
HTTPStatusCode int `json:"-"`
// Code is an internal error code string.
Code string `json:"code"`
// Message is the user-facing error message.
Message string `json:"message"`
// Details provides additional error context (optional).
Details map[string]interface{} `json:"details,omitempty"`
// Err is the underlying error (not marshaled to JSON).
Err error `json:"-"`
}
func (e *AppError) Error() string {
if e.Err != nil {
return fmt.Sprintf("%s: %v", e.Message, e.Err)
}
return e.Message
}
// Unwrap returns the underlying error.
func (e *AppError) Unwrap() error {
return e.Err
}
// ToJSON returns the JSON byte representation of the error.
func (e *AppError) ToJSON() []byte {
b, _ := json.Marshal(e)
return b
}
// New creates a new AppError.
func New(statusCode int, code, message string, err error) *AppError {
return &AppError{
HTTPStatusCode: statusCode,
Code: code,
Message: message,
Err: err,
}
}