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)
|
||||
@@ -0,0 +1,21 @@
|
||||
"""Plugin error isolation wrapper."""
|
||||
import logging
|
||||
import functools
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def wrap_plugin_route(handler):
|
||||
"""Decorator that isolates plugin route errors and returns structured JSON."""
|
||||
@functools.wraps(handler)
|
||||
async def wrapper(*args, **kwargs):
|
||||
try:
|
||||
return await handler(*args, **kwargs)
|
||||
except Exception as exc:
|
||||
logger.error(f'Plugin route error: {exc}', exc_info=True)
|
||||
return JSONResponse(
|
||||
status_code=500,
|
||||
content={'detail': f'Plugin error: {exc}', 'code': 'plugin_error'}
|
||||
)
|
||||
return wrapper
|
||||
Reference in New Issue
Block a user