diff --git a/apps/remix-ide/src/app/providers/abstract-provider.tsx b/apps/remix-ide/src/app/providers/abstract-provider.tsx index a5185b6129..ea4cc5e281 100644 --- a/apps/remix-ide/src/app/providers/abstract-provider.tsx +++ b/apps/remix-ide/src/app/providers/abstract-provider.tsx @@ -14,11 +14,15 @@ export type JsonDataResult = { id: number jsonrpc: string // version result?: any - error?: any + error?: { + code: number, + message: string + data?: string + } errorData?: any } -export type RejectRequest = (error: Error) => void +export type RejectRequest = (error: JsonDataResult) => void export type SuccessRequest = (data: JsonDataResult) => void export interface IProvider { @@ -98,7 +102,7 @@ export abstract class AbstractProvider extends Plugin implements IProvider { sendAsync(data: JsonDataRequest): Promise { // eslint-disable-next-line no-async-promise-executor return new Promise(async (resolve, reject) => { - if (!this.provider) return reject(new Error('provider node set')) + if (!this.provider) return reject({jsonrpc: '2.0', id: data.id, error: { message: 'provider node set', code: -32603 } } as JsonDataResult) this.sendAsyncInternal(data, resolve, reject) }) } @@ -128,7 +132,8 @@ export abstract class AbstractProvider extends Plugin implements IProvider { if (error && error.message && error.message.includes('net_version') && error.message.includes('SERVER_ERROR')) { this.switchAway(true) } - reject(error) + error.code = -32603 + reject({jsonrpc: '2.0', error, id: data.id}) } } else { const result = data.method === 'net_listening' ? 'canceled' : [] diff --git a/apps/remix-ide/src/app/providers/injected-provider.tsx b/apps/remix-ide/src/app/providers/injected-provider.tsx index a4273e0f31..36c7e35774 100644 --- a/apps/remix-ide/src/app/providers/injected-provider.tsx +++ b/apps/remix-ide/src/app/providers/injected-provider.tsx @@ -80,7 +80,7 @@ export abstract class InjectedProvider extends Plugin implements IProvider { this.call('notification', 'toast', 'No injected provider (e.g Metamask) has been found.') return resolve({ jsonrpc: '2.0', - error: 'no injected provider found', + error: { message: 'no injected provider found', code: -32603 }, id: data.id }) } @@ -89,7 +89,7 @@ export abstract class InjectedProvider extends Plugin implements IProvider { if (web3Provider.request) resultData = await web3Provider.request({method: data.method, params: data.params}) else if (web3Provider.send) resultData = await web3Provider.send(data.method, data.params) else { - resolve({jsonrpc: '2.0', error: 'provider not valid', id: data.id}) + resolve({jsonrpc: '2.0', error: { message: 'provider not valid', code: -32603 }, id: data.id}) return } if (resultData) { @@ -98,7 +98,7 @@ export abstract class InjectedProvider extends Plugin implements IProvider { } resolve({jsonrpc: '2.0', result: resultData, id: data.id}) } else { - resolve({jsonrpc: '2.0', error: 'no return data provided', id: data.id}) + resolve({jsonrpc: '2.0', result: null, id: data.id}) } } catch (error) { if (error.data && error.data.originalError && error.data.originalError.data) {