-
Notifications
You must be signed in to change notification settings - Fork 55
/
txSubmissionErrors.ts
36 lines (30 loc) · 1.11 KB
/
txSubmissionErrors.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { CardanoNodeErrors } from '../../CardanoNode';
import { isProductionEnvironment, stripStackTrace } from '@cardano-sdk/util';
/**
* Tests the provided error for an instanceof match in the TxSubmissionErrors object
*
* @param {CardanoNodeErrors.TxSubmissionError} error the error under test
*/
export const isTxSubmissionError = (error: unknown): error is CardanoNodeErrors.TxSubmissionError =>
Object.values(CardanoNodeErrors.TxSubmissionErrors).some((TxSubmitError) => error instanceof TxSubmitError);
/**
* Attempts to convert the provided error or array of errors into TxSubmissionError object
*
* @param {any} error the error or array of errors under test
*/
export const asTxSubmissionError = (error: unknown): CardanoNodeErrors.TxSubmissionError | null => {
if (Array.isArray(error)) {
for (const err of error) {
if (isTxSubmissionError(err)) {
if (isProductionEnvironment()) stripStackTrace(err);
return err;
}
}
return null;
}
if (isTxSubmissionError(error)) {
if (isProductionEnvironment()) stripStackTrace(error);
return error;
}
return null;
};