Skip to content

Commit

Permalink
feat: overwrite error.stack when ReactNative flag is set
Browse files Browse the repository at this point in the history
  • Loading branch information
ieow committed Feb 2, 2024
1 parent c0d505a commit 4eb5b4d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/openlogin-jrpc/src/jrpcEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ export class JRPCEngine extends SafeEventEmitter {
const end: JRPCEngineEndCallback = (err?: unknown) => {
const error = err || res.error;
if (error) {
if (globalThis.ReactNative) error.stack = "ReactNative flag is set. Stack trace is not available."

res.error = serializeError(error, {
shouldIncludeStack: true,
fallbackError: {
Expand Down Expand Up @@ -319,6 +321,8 @@ export class JRPCEngine extends SafeEventEmitter {
// Ensure no result is present on an errored response
delete res.result;
if (!res.error) {
if (globalThis.ReactNative) error.stack = "ReactNative flag is set. Stack trace is not available."

res.error = serializeError(error, {
shouldIncludeStack: true,
fallbackError: {
Expand Down Expand Up @@ -411,6 +415,8 @@ export function providerFromEngine(engine: JRPCEngine): SafeEventEmitterProvider
provider.sendAsync = async <T, U>(req: JRPCRequest<T>) => {
const res = await engine.handle(req);
if (res.error) {
if (globalThis.ReactNative) res.error.stack = "ReactNative flag is set. Stack trace is not available."

const err = serializeError(res.error, {
fallbackError: {
message: res.error?.message || res.error?.toString(),
Expand Down

0 comments on commit 4eb5b4d

Please sign in to comment.