Add full monorepo: virtual-banker, backend, frontend, docs, scripts, deployment
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
51
backend/api/rest/errors.go
Normal file
51
backend/api/rest/errors.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// ErrorResponse represents an API error response
|
||||
type ErrorResponse struct {
|
||||
Error ErrorDetail `json:"error"`
|
||||
}
|
||||
|
||||
// ErrorDetail contains error details
|
||||
type ErrorDetail struct {
|
||||
Code string `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Details string `json:"details,omitempty"`
|
||||
}
|
||||
|
||||
// writeError writes an error response
|
||||
func writeError(w http.ResponseWriter, statusCode int, code, message string) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(statusCode)
|
||||
json.NewEncoder(w).Encode(ErrorResponse{
|
||||
Error: ErrorDetail{
|
||||
Code: code,
|
||||
Message: message,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// writeNotFound writes a 404 error response
|
||||
func writeNotFound(w http.ResponseWriter, resource string) {
|
||||
writeError(w, http.StatusNotFound, "NOT_FOUND", resource+" not found")
|
||||
}
|
||||
|
||||
// writeInternalError writes a 500 error response
|
||||
func writeInternalError(w http.ResponseWriter, message string) {
|
||||
writeError(w, http.StatusInternalServerError, "INTERNAL_ERROR", message)
|
||||
}
|
||||
|
||||
// writeUnauthorized writes a 401 error response
|
||||
func writeUnauthorized(w http.ResponseWriter) {
|
||||
writeError(w, http.StatusUnauthorized, "UNAUTHORIZED", "Authentication required")
|
||||
}
|
||||
|
||||
// writeForbidden writes a 403 error response
|
||||
func writeForbidden(w http.ResponseWriter) {
|
||||
writeError(w, http.StatusForbidden, "FORBIDDEN", "Access denied")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user