Fix metamask reject error (#957)
This commit is contained in:
parent
0017d5f075
commit
3f4837c7c5
|
@ -9,7 +9,7 @@ import {
|
|||
isValidSignMessage,
|
||||
isValidGetAccounts,
|
||||
isValidGetNetVersion
|
||||
} from '../../validators';
|
||||
} from 'libs/validators';
|
||||
|
||||
export default class Web3Node extends RPCNode {
|
||||
public client: Web3Client;
|
||||
|
|
|
@ -192,8 +192,17 @@ function isValidResult(response: JsonRpcResponse, schemaFormat): boolean {
|
|||
|
||||
function formatErrors(response: JsonRpcResponse, apiType: string) {
|
||||
if (response.error) {
|
||||
// Metamask errors are sometimes full-blown stacktraces, no bueno. Instead,
|
||||
// We'll just take the first line of it, and the last thing after all of
|
||||
// the colons. An example error message would be:
|
||||
// "Error: Metamask Sign Tx Error: User rejected the signature."
|
||||
const lines = response.error.message.split('\n');
|
||||
if (lines.length > 2) {
|
||||
return lines[0].split(':').pop();
|
||||
} else {
|
||||
return `${response.error.message} ${response.error.data || ''}`;
|
||||
}
|
||||
}
|
||||
return `Invalid ${apiType} Error`;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue