Skip to content

Commit 037d554

Browse files
committed
cli: /payments: respond peer offline as E409
This was not catched because the SDK does minimal handling of PFS errors, preferring passing them through directly as promise's rejection error. We catch this specific error literally, and return a 409 response now, in line with PC's behavior
1 parent d59b9e4 commit 037d554

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

raiden-cli/src/routes/payments.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function transformSdkTransferToApiPayment(transfer: RaidenTransfer): ApiPayment
4747
};
4848
}
4949

50-
function isConflictError(error: unknown): error is RaidenError {
50+
function isTransferConflictError(error: unknown): error is RaidenError {
5151
return [
5252
ErrorCodes.PFS_INVALID_INFO,
5353
ErrorCodes.PFS_NO_ROUTES_FOUND,
@@ -59,6 +59,8 @@ function isConflictError(error: unknown): error is RaidenError {
5959
ErrorCodes.PFS_LAST_IOU_REQUEST_FAILED,
6060
ErrorCodes.PFS_IOU_SIGNATURE_MISMATCH,
6161
ErrorCodes.PFS_NO_ROUTES_BETWEEN_NODES,
62+
// PFS errors are passed through by the SDK, so we need to test literally
63+
'There is no user found online for given address.',
6264
].includes((error as Error).message);
6365
}
6466

@@ -102,10 +104,8 @@ async function doTransfer(this: Cli, request: Request, response: Response, next:
102104
response.status(402).send(error.message);
103105
} else if (isTransferFailedError(error)) {
104106
response.status(409).send(error.message);
105-
} else if (isConflictError(error)) {
106-
const errors = (error.details as { errors: string } | undefined)?.errors;
107-
const pfsErrorDetail = errors ? ` (${errors})` : '';
108-
response.status(409).json({ message: error.message, details: pfsErrorDetail });
107+
} else if (isTransferConflictError(error)) {
108+
response.status(409).json({ message: error.message, details: error.details });
109109
} else {
110110
next(error);
111111
}

0 commit comments

Comments
 (0)