Fix metamask reject error (#957)

This commit is contained in:
William O'Beirne 2018-01-29 17:17:58 -05:00 committed by Daniel Ternyak
parent 0017d5f075
commit 3f4837c7c5
2 changed files with 11 additions and 2 deletions

View File

@ -9,7 +9,7 @@ import {
isValidSignMessage,
isValidGetAccounts,
isValidGetNetVersion
} from '../../validators';
} from 'libs/validators';
export default class Web3Node extends RPCNode {
public client: Web3Client;

View File

@ -192,7 +192,16 @@ function isValidResult(response: JsonRpcResponse, schemaFormat): boolean {
function formatErrors(response: JsonRpcResponse, apiType: string) {
if (response.error) {
return `${response.error.message} ${response.error.data || ''}`;
// 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`;
}