Skip to content

Commit 583cc7e

Browse files
committed
Recursively include error causes in API responses
1 parent 01f4b62 commit 583cc7e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/api/api-model.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as _ from 'lodash';
22
import * as os from 'os';
33

4-
import { delay } from '@httptoolkit/util';
4+
import { ErrorLike, delay } from '@httptoolkit/util';
55
import { generateSPKIFingerprint } from 'mockttp';
66
import { getSystemProxy } from 'os-proxy-config';
77

@@ -197,10 +197,7 @@ export class ApiModel {
197197
success: false,
198198
metadata: activationError.metadata,
199199
error: activationError.reportable !== false
200-
? {
201-
code: activationError.code,
202-
message: activationError.message
203-
}
200+
? serializeError(activationError)
204201
: false
205202
};
206203
}
@@ -223,6 +220,12 @@ export class ApiModel {
223220

224221
}
225222

223+
const serializeError = (error: ErrorLike): {} => ({
224+
message: error.message,
225+
code: error.code,
226+
cause: error.cause ? serializeError(error.cause) : undefined
227+
});
228+
226229
// Wait for a promise, falling back to defaultValue on error or timeout
227230
const withFallback = <R>(p: () => Promise<R>, timeoutMs: number, defaultValue: R) =>
228231
Promise.race([

0 commit comments

Comments
 (0)