diff --git a/rhodecode/api/__init__.py b/rhodecode/api/__init__.py --- a/rhodecode/api/__init__.py +++ b/rhodecode/api/__init__.py @@ -122,7 +122,7 @@ def jsonrpc_response(request, result): return response -def jsonrpc_error(request, message, retid=None, code=None): +def jsonrpc_error(request, message, retid=None, code=None, headers=None): """ Generate a Response object with a JSON-RPC error body @@ -132,10 +132,12 @@ def jsonrpc_error(request, message, reti """ err_dict = {'id': retid, 'result': None, 'error': message} body = render(DEFAULT_RENDERER, err_dict, request=request).encode('utf-8') + return Response( body=body, status=code, - content_type='application/json' + content_type='application/json', + headerlist=headers ) @@ -287,8 +289,7 @@ def request_view(request): }) # register some common functions for usage - attach_context_attributes( - TemplateArgs(), request, request.rpc_user.user_id) + attach_context_attributes(TemplateArgs(), request, request.rpc_user.user_id) try: ret_value = func(**call_params) @@ -298,9 +299,13 @@ def request_view(request): except Exception: log.exception('Unhandled exception occurred on api call: %s', func) exc_info = sys.exc_info() - store_exception(id(exc_info), exc_info, prefix='rhodecode-api') + exc_id, exc_type_name = store_exception( + id(exc_info), exc_info, prefix='rhodecode-api') + error_headers = [('RhodeCode-Exception-Id', str(exc_id)), + ('RhodeCode-Exception-Type', str(exc_type_name))] return jsonrpc_error( - request, retid=request.rpc_id, message='Internal server error') + request, retid=request.rpc_id, message='Internal server error', + headers=error_headers) def setup_request(request): diff --git a/rhodecode/lib/exc_tracking.py b/rhodecode/lib/exc_tracking.py --- a/rhodecode/lib/exc_tracking.py +++ b/rhodecode/lib/exc_tracking.py @@ -115,6 +115,7 @@ def store_exception(exc_id, exc_info, pr exc_type_name, exc_traceback = _prepare_exception(exc_info) _store_exception(exc_id=exc_id, exc_type_name=exc_type_name, exc_traceback=exc_traceback, prefix=prefix) + return exc_id, exc_type_name except Exception: log.exception('Failed to store exception `%s` information', exc_id) # there's no way this can fail, it will crash server badly if it does.