|
@@ -86,6 +86,23 @@ export async function tryDo<TResult>(promise: Promise<TResult>) : Promise<{ok: b
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+export async function assertOk<T>(promise: Promise<T>): Promise<T> {
|
|
|
|
+ try {
|
|
|
|
+ return await promise;
|
|
|
|
+ } catch (err) {
|
|
|
|
+ if (hasStackTrace(err)) {
|
|
|
|
+ const trace: {stack?: string} = {};
|
|
|
|
+ Error.captureStackTrace(trace);
|
|
|
|
+ err.stack = `${err.stack}\nCaused by: ${trace.stack}`;
|
|
|
|
+ }
|
|
|
|
+ throw err;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
export function isHttpError(err?: unknown): err is HTTPError {
|
|
export function isHttpError(err?: unknown): err is HTTPError {
|
|
return err && Object.prototype.hasOwnProperty.call(err, "response");
|
|
return err && Object.prototype.hasOwnProperty.call(err, "response");
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+export function hasStackTrace(reason?: unknown): reason is {stack: unknown} {
|
|
|
|
+ return reason && Object.prototype.hasOwnProperty.call(reason, "stack");
|
|
}
|
|
}
|