-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signer Implement global error handling [sc-13127] (#210)
- Loading branch information
1 parent
8dcaea3
commit a6a4a2a
Showing
12 changed files
with
104 additions
and
152 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
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
41 changes: 41 additions & 0 deletions
41
examples/react-signer/src/service/exception-handler.service.ts
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { RPCMessage } from "../type" | ||
|
||
export class NotSupportedError extends Error {} | ||
export class GenericError extends Error {} | ||
|
||
class ExceptionHandlerService { | ||
public handle(error: unknown, message: MessageEvent<RPCMessage>) { | ||
console.error("ExceptionHandlerService", error) | ||
|
||
if (error instanceof NotSupportedError) { | ||
this.postErrorMessage(message, 2000, "Not supported") | ||
} | ||
|
||
if (error instanceof GenericError) { | ||
this.postErrorMessage(message, 1000, "Generic error", error.message) | ||
} | ||
} | ||
|
||
private postErrorMessage( | ||
message: MessageEvent<RPCMessage>, | ||
code: number, | ||
title: string, | ||
text?: string | ||
) { | ||
window.parent.postMessage( | ||
{ | ||
origin: message.data.origin, | ||
jsonrpc: message.data.jsonrpc, | ||
id: message.data.id, | ||
error: { | ||
code, | ||
message: title, | ||
text, | ||
}, | ||
}, | ||
message.origin | ||
) | ||
} | ||
} | ||
|
||
export const exceptionHandlerService = new ExceptionHandlerService() |
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
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
Oops, something went wrong.