-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify stack track merging to fix source maps.
- Loading branch information
Showing
2 changed files
with
52 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,32 @@ | ||
class CustomError extends Error { | ||
constructor(message: string, previousError: unknown) { | ||
const prevStack = (previousError as Error)?.stack || ''; | ||
originalError?: Error; | ||
|
||
constructor(originalError: unknown) { | ||
const isOrigErrorValid = originalError instanceof Error; | ||
const prevStackLines = isOrigErrorValid | ||
? originalError.stack?.split('\n') | ||
: []; | ||
|
||
super(isOrigErrorValid | ||
? `${originalError.name}: ${originalError.message}` | ||
: ''); | ||
|
||
super(message); | ||
this.name = this.constructor.name; | ||
if (isOrigErrorValid) { | ||
this.originalError = originalError; | ||
} | ||
|
||
if (prevStack && this.stack) { | ||
if (prevStackLines?.length && this.stack) { | ||
this.stack = this.stack | ||
.split('\n') | ||
.slice(0, 2) | ||
.concat(prevStack) | ||
.concat( | ||
prevStackLines.slice(1, prevStackLines.length) | ||
) | ||
.join('\n'); | ||
} | ||
} | ||
} | ||
|
||
export class PersistError extends CustomError { | ||
constructor(previousError: unknown) { | ||
super('redux-remember: persist error', previousError); | ||
} | ||
} | ||
|
||
export class RehydrateError extends CustomError { | ||
constructor(previousError: unknown) { | ||
super('redux-remember: rehydrate error', previousError); | ||
} | ||
} | ||
export class PersistError extends CustomError {} | ||
export class RehydrateError extends CustomError {} |