##// END OF EJS Templates
exception-tracker: send exc id headers on failed API calls for tracking errors that server generated.
marcink -
r4112:1f5dcb79 default
parent child Browse files
Show More
@@ -122,7 +122,7 b' def jsonrpc_response(request, result):'
122 return response
122 return response
123
123
124
124
125 def jsonrpc_error(request, message, retid=None, code=None):
125 def jsonrpc_error(request, message, retid=None, code=None, headers=None):
126 """
126 """
127 Generate a Response object with a JSON-RPC error body
127 Generate a Response object with a JSON-RPC error body
128
128
@@ -132,10 +132,12 b' def jsonrpc_error(request, message, reti'
132 """
132 """
133 err_dict = {'id': retid, 'result': None, 'error': message}
133 err_dict = {'id': retid, 'result': None, 'error': message}
134 body = render(DEFAULT_RENDERER, err_dict, request=request).encode('utf-8')
134 body = render(DEFAULT_RENDERER, err_dict, request=request).encode('utf-8')
135
135 return Response(
136 return Response(
136 body=body,
137 body=body,
137 status=code,
138 status=code,
138 content_type='application/json'
139 content_type='application/json',
140 headerlist=headers
139 )
141 )
140
142
141
143
@@ -287,8 +289,7 b' def request_view(request):'
287 })
289 })
288
290
289 # register some common functions for usage
291 # register some common functions for usage
290 attach_context_attributes(
292 attach_context_attributes(TemplateArgs(), request, request.rpc_user.user_id)
291 TemplateArgs(), request, request.rpc_user.user_id)
292
293
293 try:
294 try:
294 ret_value = func(**call_params)
295 ret_value = func(**call_params)
@@ -298,9 +299,13 b' def request_view(request):'
298 except Exception:
299 except Exception:
299 log.exception('Unhandled exception occurred on api call: %s', func)
300 log.exception('Unhandled exception occurred on api call: %s', func)
300 exc_info = sys.exc_info()
301 exc_info = sys.exc_info()
301 store_exception(id(exc_info), exc_info, prefix='rhodecode-api')
302 exc_id, exc_type_name = store_exception(
303 id(exc_info), exc_info, prefix='rhodecode-api')
304 error_headers = [('RhodeCode-Exception-Id', str(exc_id)),
305 ('RhodeCode-Exception-Type', str(exc_type_name))]
302 return jsonrpc_error(
306 return jsonrpc_error(
303 request, retid=request.rpc_id, message='Internal server error')
307 request, retid=request.rpc_id, message='Internal server error',
308 headers=error_headers)
304
309
305
310
306 def setup_request(request):
311 def setup_request(request):
@@ -115,6 +115,7 b' def store_exception(exc_id, exc_info, pr'
115 exc_type_name, exc_traceback = _prepare_exception(exc_info)
115 exc_type_name, exc_traceback = _prepare_exception(exc_info)
116 _store_exception(exc_id=exc_id, exc_type_name=exc_type_name,
116 _store_exception(exc_id=exc_id, exc_type_name=exc_type_name,
117 exc_traceback=exc_traceback, prefix=prefix)
117 exc_traceback=exc_traceback, prefix=prefix)
118 return exc_id, exc_type_name
118 except Exception:
119 except Exception:
119 log.exception('Failed to store exception `%s` information', exc_id)
120 log.exception('Failed to store exception `%s` information', exc_id)
120 # there's no way this can fail, it will crash server badly if it does.
121 # there's no way this can fail, it will crash server badly if it does.
General Comments 0
You need to be logged in to leave comments. Login now