<s> from __future__ import unicode_literals <EOL> from pyramid . view import view_config <EOL> from pyramid . renderers import render_to_response <EOL> from pyramid . security import NO_PERMISSION_REQUIRED <EOL> from billy . errors import BillyError <EOL> from billy . models . subscription import SubscriptionCanceledError <EOL> from billy . models . invoice import InvalidOperationError <EOL> from billy . models . invoice import DuplicateExternalIDError <EOL> from billy . models . processors . balanced_payments import InvalidURIFormat <EOL> DEFAULT_ERROR_STATUS_CODE = <NUM_LIT> <EOL> ERROR_STATUS_MAP = { <EOL> SubscriptionCanceledError : <NUM_LIT> , <EOL> InvalidOperationError : <NUM_LIT> , <EOL> DuplicateExternalIDError : <NUM_LIT> , <EOL> InvalidURIFormat : <NUM_LIT> , <EOL> } <EOL> def error_response ( request , error , status ) : <EOL> """<STR_LIT>""" <EOL> response = render_to_response ( <EOL> renderer_name = '<STR_LIT>' , <EOL> value = dict ( <EOL> error_class = error . __class__ . __name__ , <EOL> error_message = error . msg , <EOL> ) , <EOL> request = request , <EOL> ) <EOL> response . status = status <EOL> return response <EOL> @ view_config ( <EOL> context = BillyError , <EOL> permission = NO_PERMISSION_REQUIRED , <EOL> ) <EOL> def display_error ( error , request ) : <EOL> cls = type ( error ) <EOL> status = ERROR_STATUS_MAP . get ( cls , DEFAULT_ERROR_STATUS_CODE ) <EOL> return error_response ( request , error , status ) </s>
