feat: add forgejo_error_reporter plugin for automatic error reporting to Forgejo issues
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
"""Standardized error codes for consistent frontend handling."""
|
||||
|
||||
ERROR_CODES = {
|
||||
'not_found': {'status': 404, 'message': 'Resource not found'},
|
||||
'permission_denied': {'status': 403, 'message': 'Permission denied'},
|
||||
'validation_error': {'status': 422, 'message': 'Validation failed'},
|
||||
'rate_limited': {'status': 429, 'message': 'Too many requests'},
|
||||
'internal_error': {'status': 500, 'message': 'Internal server error'},
|
||||
'service_unavailable': {'status': 503, 'message': 'Service temporarily unavailable'},
|
||||
}
|
||||
|
||||
|
||||
class ApiError(Exception):
|
||||
def __init__(self, code: str, detail: str = None, field: str = None, status: int = None):
|
||||
self.code = code
|
||||
self.detail = detail or ERROR_CODES.get(code, {}).get('message', 'Unknown error')
|
||||
self.field = field
|
||||
self.status = status or ERROR_CODES.get(code, {}).get('status', 500)
|
||||
super().__init__(self.detail)
|
||||
Reference in New Issue
Block a user