Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix setting stack on strings #313

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/openlogin-jrpc/src/jrpcEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ export class JRPCEngine extends SafeEventEmitter {
const end: JRPCEngineEndCallback = (err?: unknown) => {
const error = err || res.error;
if (error) {
if (Object.keys(error).includes("stack") === false) error.stack = "Stack trace is not available.";
if (typeof error === "object" && Object.keys(error).includes("stack") === false) error.stack = "Stack trace is not available.";

res.error = serializeError(error, {
shouldIncludeStack: true,
fallbackError: {
message: error?.message || error?.toString(),
code: error?.code || -32603,
stack: error?.stack,
stack: error?.stack || "Stack trace is not available.",
data: error?.data || error?.message || error?.toString(),
},
});
Expand Down Expand Up @@ -321,14 +321,14 @@ export class JRPCEngine extends SafeEventEmitter {
// Ensure no result is present on an errored response
delete res.result;
if (!res.error) {
if (Object.keys(error).includes("stack") === false) error.stack = "Stack trace is not available.";
if (typeof error === "object" && Object.keys(error).includes("stack") === false) error.stack = "Stack trace is not available.";

res.error = serializeError(error, {
shouldIncludeStack: true,
fallbackError: {
message: error?.message || error?.toString(),
code: (error as { code?: number })?.code || -32603,
stack: error?.stack,
stack: error?.stack || "Stack trace is not available.",
data: (error as { data?: string })?.data || error?.message || error?.toString(),
},
});
Expand Down Expand Up @@ -415,13 +415,13 @@ export function providerFromEngine(engine: JRPCEngine): SafeEventEmitterProvider
provider.sendAsync = async <T, U>(req: JRPCRequest<T>) => {
const res = await engine.handle(req);
if (res.error) {
if (Object.keys(res.error).includes("stack") === false) res.error.stack = "Stack trace is not available.";
if (typeof res.error === "object" && Object.keys(res.error).includes("stack") === false) res.error.stack = "Stack trace is not available.";

const err = serializeError(res.error, {
fallbackError: {
message: res.error?.message || res.error?.toString(),
code: res.error?.code || -32603,
stack: res.error?.stack,
stack: res.error?.stack || "Stack trace is not available.",
data: res.error?.data || res.error?.message || res.error?.toString(),
},
shouldIncludeStack: true,
Expand Down
Loading