def format_exception(excinfo, debug=False): """Extract informations that can be sent to the client.""" error = excinfo[1] code = getattr(error, 'code', None) if code and utils.is_valid_code(code) and utils.is_client_error(code): faultstring = (error.faultstring if hasattr(error, 'faultstring') else six.text_type(error)) r = dict(faultcode="Client", faultstring=faultstring) log.debug("Client-side error: %s" % r['faultstring']) r['debuginfo'] = None return r else: faultstring = six.text_type(error) debuginfo = "\n".join(traceback.format_exception(*excinfo)) log.error('Server-side error: "%s". Detail: \n%s' % ( faultstring, debuginfo)) r = dict(faultcode="Server", faultstring=faultstring) if debug: r['debuginfo'] = debuginfo else: r['debuginfo'] = None return r