Skip to content

Commit

Permalink
Simplified error details in path epic
Browse files Browse the repository at this point in the history
  • Loading branch information
nephix committed Feb 18, 2020
1 parent 222162b commit 102033f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 20 deletions.
2 changes: 1 addition & 1 deletion raiden-ts/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const getContracts = (network: Network): ContractsInfo => {
...goerliServicesDeploy.contracts,
} as unknown) as ContractsInfo;
default:
throw new RaidenError(ErrorCodes.RDN_UNRECOGNIZED_NETWORK, [{ network }]);
throw new RaidenError(ErrorCodes.RDN_UNRECOGNIZED_NETWORK, [{ network: network.name }]);
}
};

Expand Down
8 changes: 3 additions & 5 deletions raiden-ts/src/path/epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ const prepareNextIOU$ = (
const text = await response.text();
if (!response.ok)
throw new RaidenError(ErrorCodes.PFS_LAST_IOU_REQUEST_FAILED, [
{ responseStatus: response.status },
{ responseText: text },
{ responseStatus: response.status, responseText: text },
]);

const { last_iou: lastIou } = decode(LastIOUResults, losslessParse(text));
Expand All @@ -160,8 +159,8 @@ const prepareNextIOU$ = (
throw new RaidenError(ErrorCodes.PFS_IOU_SIGNATURE_MISMATCH, [
{
signer,
address: deps.address,
},
{ address: deps.address },
]);
return lastIou;
}),
Expand Down Expand Up @@ -334,8 +333,7 @@ export const pathFindServiceEpic = (
// if error, don't proceed
if (!data.paths) {
throw new RaidenError(ErrorCodes.PFS_ERROR_RESPONSE, [
{ errorCode: data.error.error_code },
{ errors: data.error.errors },
{ errorCode: data.error.error_code, errors: data.error.errors },
]);
}
const filteredPaths: Paths = [],
Expand Down
2 changes: 1 addition & 1 deletion raiden-ts/src/transport/epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ export const matrixPresenceUpdateEpic = (
const recovered = verifyMessage(userId, displayName) as Address | undefined;
if (!recovered || recovered !== address)
throw new RaidenError(ErrorCodes.TRNS_USERNAME_VERIFICATION_FAILED, [
{ userId, receivedSignature: recovered },
{ userId, receivedSignature: recovered! },
]);
return recovered;
}),
Expand Down
4 changes: 2 additions & 2 deletions raiden-ts/src/utils/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export enum ErrorCodes {

// Channel errors
CNL_INVALID_STATE = 'Invalid channel state.',
CNL_TOKEN_NOT_FOUND = 'Could not find tken for token network.',
CNL_TOKEN_NOT_FOUND = 'Could not find token for token network.',
CNL_NO_OPEN_CHANNEL_FOUND = 'No open channel has been found.',
CNL_NO_OPEN_OR_CLOSING_CHANNEL_FOUND = 'No open or closing channel has been found.',
CNL_NO_SETTLEABLE_OR_SETTLING_CHANNEL_FOUND = 'No settleable or settling channel has been found.',
Expand Down Expand Up @@ -49,7 +49,7 @@ export enum ErrorCodes {
RDN_UNRECOGNIZED_NETWORK = 'No deploy info provided nor recognized network.',
RDN_SIGNER_NOT_CONNECTED = 'The signing account is not connected to the provider.',
RDN_ACCOUNT_NOT_FOUND = 'Account not found in provider.',
RDN_STRING_ACCOUNT_INVALID = 'String account must be either a 0x-encoded address or private key',
RDN_STRING_ACCOUNT_INVALID = 'String account must be either a 0x-encoded address or private key.',
}

export const ErrorDetails = t.array(t.record(t.string, t.union([t.string, t.number])));
Expand Down
21 changes: 10 additions & 11 deletions raiden-ts/tests/unit/epics/path.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ describe('PFS: pathFindServiceEpic', () => {
pathFind.failure(
expect.objectContaining({
message: ErrorCodes.PFS_ERROR_RESPONSE,
details: [{ errorCode: 1337 }, { errors: 'No route' }],
details: [{ errorCode: 1337, errors: 'No route' }],
}),
{ tokenNetwork, target, value },
),
Expand Down Expand Up @@ -925,10 +925,7 @@ describe('PFS: pathFindServiceEpic', () => {
pathFind.failure(
expect.objectContaining({
message: ErrorCodes.PFS_ERROR_RESPONSE,
details: expect.arrayContaining([
{ errorCode: 2201 },
{ errors: 'No route between nodes found.' },
]),
details: [{ errorCode: 2201, errors: 'No route between nodes found.' }],
}),
{ tokenNetwork, target, value },
),
Expand Down Expand Up @@ -975,7 +972,7 @@ describe('PFS: pathFindServiceEpic', () => {
pathFind.failure(
expect.objectContaining({
message: ErrorCodes.PFS_LAST_IOU_REQUEST_FAILED,
details: expect.arrayContaining([{ responseStatus: 500 }, { responseText: '{}' }]),
details: [{ responseStatus: 500, responseText: '{}' }],
}),
{ tokenNetwork, target, value },
),
Expand Down Expand Up @@ -1031,8 +1028,10 @@ describe('PFS: pathFindServiceEpic', () => {
expect.objectContaining({
message: ErrorCodes.PFS_IOU_SIGNATURE_MISMATCH,
details: expect.arrayContaining([
{ signer: '0x9EE8539c8C7215AcAE56Fed72E7035a307e24989' },
{ address: '0x14791697260E4c9A71f18484C9f997B308e59325' },
{
signer: '0x9EE8539c8C7215AcAE56Fed72E7035a307e24989',
address: '0x14791697260E4c9A71f18484C9f997B308e59325',
},
]),
}),
{ tokenNetwork, target, value },
Expand Down Expand Up @@ -1101,13 +1100,13 @@ describe('PFS: pathFindServiceEpic', () => {
pathFind.failure(
expect.objectContaining({
message: ErrorCodes.PFS_ERROR_RESPONSE,
details: expect.arrayContaining([
details: [
{
errors:
'The IOU is already claimed. Please start new session with different `expiration_block`.',
errorCode: 2105,
},
{ errorCode: 2105 },
]),
],
}),
{ tokenNetwork, target, value },
),
Expand Down

0 comments on commit 102033f

Please sign in to comment.