Skip to content

Commit

Permalink
add error stack
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitanyapotti committed Jan 11, 2024
1 parent 3ee03e1 commit 0bfaba2
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/openlogin-jrpc/src/jrpcEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class JRPCEngine extends SafeEventEmitter {
const end: JRPCEngineEndCallback = (err?: unknown) => {
const error = err || res.error;
if (error) {
res.error = serializeError(error);
res.error = serializeError(error, { shouldIncludeStack: true });
}
// True indicates that the request should end
resolve([error, true]);
Expand Down Expand Up @@ -264,12 +264,14 @@ export class JRPCEngine extends SafeEventEmitter {
* A promise-wrapped _handle.
*/
private _promiseHandle(req: JRPCRequest<unknown>): Promise<JRPCResponse<unknown>> {
return new Promise((resolve) => {
return new Promise((resolve, reject) => {
this._handle(req, (_err, res) => {
// There will always be a response, and it will always have any error
// that is caught and propagated.
resolve(res);
});
if (_err && res === undefined) {
reject(_err);
} else resolve(res);
}).catch(reject);
});
}

Expand Down Expand Up @@ -309,7 +311,7 @@ export class JRPCEngine extends SafeEventEmitter {
// Ensure no result is present on an errored response
delete res.result;
if (!res.error) {
res.error = serializeError(error);
res.error = serializeError(error, { shouldIncludeStack: true });
}
}

Expand Down Expand Up @@ -398,6 +400,7 @@ export function providerFromEngine(engine: JRPCEngine): SafeEventEmitterProvider
message: res.error?.message || res.error.toString(),
code: res.error?.code || -32603,
},
shouldIncludeStack: true,
});

throw rpcErrors.internal(err);
Expand Down

0 comments on commit 0bfaba2

Please sign in to comment.