|  | @@ -4,6 +4,7 @@ import typing
 | 
	
		
			
			| 4 | 4 |  from http import HTTPStatus
 | 
	
		
			
			| 5 | 5 |  
 | 
	
		
			
			| 6 | 6 |  # TODO BS 20171010: bottle specific !  # see #5
 | 
	
		
			
			|  | 7 | +import marshmallow
 | 
	
		
			
			| 7 | 8 |  from bottle import HTTPResponse
 | 
	
		
			
			| 8 | 9 |  
 | 
	
		
			
			| 9 | 10 |  from hapic.data import HapicData
 | 
	
	
		
			
			|  | @@ -338,11 +339,13 @@ class ExceptionHandlerControllerWrapper(ControllerWrapper):
 | 
	
		
			
			| 338 | 339 |          self,
 | 
	
		
			
			| 339 | 340 |          handled_exception_class: typing.Type[Exception],
 | 
	
		
			
			| 340 | 341 |          context: typing.Union[ContextInterface, typing.Callable[[], ContextInterface]],  # nopep8
 | 
	
		
			
			|  | 342 | +        schema: marshmallow.Schema,
 | 
	
		
			
			| 341 | 343 |          http_code: HTTPStatus=HTTPStatus.INTERNAL_SERVER_ERROR,
 | 
	
		
			
			| 342 | 344 |      ) -> None:
 | 
	
		
			
			| 343 | 345 |          self.handled_exception_class = handled_exception_class
 | 
	
		
			
			| 344 | 346 |          self._context = context
 | 
	
		
			
			| 345 | 347 |          self.http_code = http_code
 | 
	
		
			
			|  | 348 | +        self.schema = schema
 | 
	
		
			
			| 346 | 349 |  
 | 
	
		
			
			| 347 | 350 |      @property
 | 
	
		
			
			| 348 | 351 |      def context(self) -> ContextInterface:
 | 
	
	
		
			
			|  | @@ -363,16 +366,17 @@ class ExceptionHandlerControllerWrapper(ControllerWrapper):
 | 
	
		
			
			| 363 | 366 |                  func_kwargs,
 | 
	
		
			
			| 364 | 367 |              )
 | 
	
		
			
			| 365 | 368 |          except self.handled_exception_class as exc:
 | 
	
		
			
			| 366 |  | -            # TODO: error_dict configurable name, see #4
 | 
	
		
			
			| 367 |  | -            # TODO: Who assume error structure ? We have to rethink it, see #4
 | 
	
		
			
			| 368 |  | -            error_dict = {
 | 
	
		
			
			| 369 |  | -                'error_message': str(exc),
 | 
	
		
			
			|  | 369 | +            # TODO: "error_detail" attribute name should be configurable
 | 
	
		
			
			|  | 370 | +            # TODO BS 20171013: use overrideable mechanism, error object given
 | 
	
		
			
			|  | 371 | +            #  to schema ? see #15
 | 
	
		
			
			|  | 372 | +            raw_response = {
 | 
	
		
			
			|  | 373 | +                'message': str(exc),
 | 
	
		
			
			|  | 374 | +                'code': None,
 | 
	
		
			
			|  | 375 | +                'detail': getattr(exc, 'error_detail', {}),
 | 
	
		
			
			| 370 | 376 |              }
 | 
	
		
			
			| 371 |  | -            if hasattr(exc, 'error_dict'):
 | 
	
		
			
			| 372 |  | -                error_dict.update(exc.error_dict)
 | 
	
		
			
			| 373 | 377 |  
 | 
	
		
			
			| 374 | 378 |              error_response = self.context.get_response(
 | 
	
		
			
			| 375 |  | -                error_dict,
 | 
	
		
			
			|  | 379 | +                raw_response,
 | 
	
		
			
			| 376 | 380 |                  self.http_code,
 | 
	
		
			
			| 377 | 381 |              )
 | 
	
		
			
			| 378 | 382 |              return error_response
 |