code: def protorpc_to_endpoints_error(self, status, body):
      
      try:
        rpc_error = self.__PROTOJSON.decode_message(remote.RpcStatus, body)
      except (ValueError, messages.ValidationError):
        rpc_error = remote.RpcStatus()
  
      if rpc_error.state == remote.RpcStatus.State.APPLICATION_ERROR:
  
        # Try to map to HTTP error code.
        error_class = _ERROR_NAME_MAP.get(rpc_error.error_name)
        if error_class:
          status, body = self.__write_error(error_class.http_status,
                                            rpc_error.error_message)
      return status, body
docs: Convert a ProtoRPC error to the format expected by Google Endpoints.
  
      If the body does not contain an ProtoRPC message in state APPLICATION_ERROR
      the status and body will be returned unchanged.
  
      Args:
        status: HTTP status of the response from the backend
        body: JSON-encoded error in format expected by Endpoints frontend.
  
      Returns:
        Tuple of (http status, body)