MCPcopy Create free account
hub / github.com/B3Pay/B3Wallet / errorHandler

Function errorHandler

src/lib/utils.ts:6–41  ·  view source on GitHub ↗
(error: Error | unknown | null)

Source from the content-addressed store, hash-verified

4import { twMerge } from "tailwind-merge"
5
6export const errorHandler = (error: Error | unknown | null): string => {
7 // Check if an error was passed
8 if (!error) {
9 // Return an empty string if no error was passed
10 return ""
11 }
12
13 const errorString = error.toString()
14
15 // Regular expression to match the specific error text
16 // Error: Call was rejected:
17 // Request ID: c2eb7e506a48634d1f839095cea252f0b99171807b576a4518b26260bb9dbd53
18 // Reject code: 5
19 // Reject text: Canister bkyz2-fmaaa-aaaaa-qaaaq-cai trapped explicitly: User already exists!
20 const regex = /Reject text: (.*)/
21
22 // Use the regular expression to find the error message
23 const match = errorString.match(regex)
24
25 // Check if a match was found
26 if (match && match[1]) {
27 // Return the extracted error message
28 return match[1]
29 } else {
30 const regex2 = /"Message": (.*)/
31
32 const match2 = errorString.match(regex2)
33
34 if (match2 && match2[1]) {
35 return match2[1]
36 }
37
38 // Return a generic error message if no specific message was found
39 return "An unknown error occurred."
40 }
41}
42
43export const objectToString = (data: any) => {
44 return JSON.stringify(

Callers 2

DisplayDataFunction · 0.90
AppFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected