<s> import json <EOL> from nameko . web . handlers import HttpRequestHandler <EOL> from werkzeug . wrappers import Response <EOL> from nameko . exceptions import safe_for_serialization <EOL> class HttpError ( Exception ) : <EOL> error_code = '<STR_LIT>' <EOL> status_code = <NUM_LIT> <EOL> class InvalidArgumentsError ( HttpError ) : <EOL> error_code = '<STR_LIT>' <EOL> class HttpEntrypoint ( HttpRequestHandler ) : <EOL> def response_from_exception ( self , exc ) : <EOL> if isinstance ( exc , HttpError ) : <EOL> response = Response ( <EOL> json . dumps ( { <EOL> '<STR_LIT:error>' : exc . error_code , <EOL> '<STR_LIT:message>' : safe_for_serialization ( exc ) , <EOL> } ) , <EOL> status = exc . status_code , <EOL> mimetype = '<STR_LIT:application/json>' <EOL> ) <EOL> return response <EOL> return HttpRequestHandler . response_from_exception ( self , exc ) <EOL> http = HttpEntrypoint . decorator <EOL> class Service ( object ) : <EOL> name = "<STR_LIT>" <EOL> @ http ( '<STR_LIT:GET>' , '<STR_LIT>' ) <EOL> def custom_exception ( self , request ) : <EOL> raise InvalidArgumentsError ( "<STR_LIT>" ) </s>
