mirror of
				https://github.com/Telecominfraproject/oopt-gnpy-api.git
				synced 2025-10-31 09:57:50 +00:00 
			
		
		
		
	refactor: API now rely on gnpy function without re-implementation
Change-Id: Ib71f62f74eaa9fd87606a977f1f2c830b71668d9
This commit is contained in:
		
							
								
								
									
										34
									
								
								gnpyapi/core/exception/exception_handler.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								gnpyapi/core/exception/exception_handler.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,34 @@ | ||||
| # coding: utf-8 | ||||
| import json | ||||
| import re | ||||
|  | ||||
| import werkzeug | ||||
|  | ||||
| from gnpyapi.core.model.error import Error | ||||
|  | ||||
| _reaesc = re.compile(r'\x1b[^m]*m') | ||||
|  | ||||
|  | ||||
| def common_error_handler(exception): | ||||
|     """ | ||||
|  | ||||
|     :type exception: Exception | ||||
|  | ||||
|     """ | ||||
|     status_code = 500 | ||||
|     if not isinstance(exception, werkzeug.exceptions.HTTPException): | ||||
|         exception = werkzeug.exceptions.InternalServerError() | ||||
|         exception.description = "Something went wrong on our side." | ||||
|     else: | ||||
|         status_code = exception.code | ||||
|     response = Error(message=exception.name, description=exception.description, | ||||
|                      code=status_code) | ||||
|  | ||||
|     return werkzeug.Response(response=json.dumps(response.__dict__), status=status_code, mimetype='application/json') | ||||
|  | ||||
|  | ||||
| def bad_request_handler(exception): | ||||
|     exception_str = " ".join(str(exception).split()) | ||||
|     response = Error(message='bad request', description=_reaesc.sub('', exception_str.replace("\n", " ")), | ||||
|                      code=400) | ||||
|     return werkzeug.Response(response=json.dumps(response.__dict__), status=400, mimetype='application/json') | ||||
		Reference in New Issue
	
	Block a user
	 Renato Ambrosone
					Renato Ambrosone