def json_error_handler(request):
 errors = request.errors
 sorted_errors = sorted(errors, key=(lambda x: six.text_type(x['name'])))
 error = sorted_errors[0]
 name = error['name']
 description = error['description']
 if isinstance(description, six.binary_type):
  description = error['description'].decode('utf-8')
 if (name is not None):
  if (name in description):
   message = description
  else:
   message = ('%(name)s in %(location)s: %(description)s' % error)
 else:
  message = ('%(location)s: %(description)s' % error)
 response = http_error(httpexceptions.HTTPBadRequest(), code=errors.status, errno=ERRORS.INVALID_PARAMETERS.value, error='Invalid parameters', message=message, details=errors)
 response.status = errors.status
 response = reapply_cors(request, response)
 return response

def json_error_handler ( request ) : errors = request . errors sorted_errors = sorted ( errors , key = ( lambda x : six . text_type ( x [ 'name' ] ) ) ) error = sorted_errors [ 0 ] name = error [ 'name' ] description = error [ 'description' ] if isinstance ( description , six . binary_type ) : description = error [ 'description' ] . decode ( 'utf-8' ) if ( name is not None ) : if ( name in description ) : message = description else : message = ( '%(name)s in %(location)s: %(description)s' % error ) else : message = ( '%(location)s: %(description)s' % error ) response = http_error ( httpexceptions . HTTPBadRequest ( ) , code = errors . status , errno = ERRORS . INVALID_PARAMETERS . value , error = 'Invalid parameters' , message = message , details = errors ) response . status = errors . status response = reapply_cors ( request , response ) return response
cornice json error handler .