Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
protected _formatResponse (
response: Partial
): IJsonRpcResponseSuccess | IJsonRpcResponseError {
if (typeof response.id === 'undefined') {
throw new Error(ERROR_MISSING_ID)
}
if (isJsonRpcResponseError(response)) {
const error = formatRpcError(response.error)
const errorResponse: IJsonRpcResponseError = {
id: response.id,
jsonrpc: '2.0',
...response,
error
}
return errorResponse
} else if (isJsonRpcResponseSuccess(response)) {
const successResponse: IJsonRpcResponseSuccess = {
id: response.id,
jsonrpc: '2.0',
...response
}
return successResponse