File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -42,8 +42,33 @@ const listenToRendererCalls = (
42
42
} )
43
43
}
44
44
45
+ function extractJSONAfterError ( input : string ) : object | null {
46
+ try {
47
+ // Match the pattern where "error=" precedes a JSON string
48
+ const errorPattern = / e r r o r = ( \{ [ ^ { } ] * \} ) /
49
+
50
+ const match = input . match ( errorPattern )
51
+
52
+ if ( match && match [ 1 ] ) {
53
+ // Parse the JSON string captured by the regex
54
+ return JSON . parse ( match [ 1 ] )
55
+ }
56
+
57
+ // Return null if no valid JSON is found
58
+ return null
59
+ } catch ( error ) {
60
+ console . error ( 'Error parsing JSON:' , error )
61
+ return null
62
+ }
63
+ }
64
+
45
65
const provRequest = async ( args : RequestArguments ) => {
46
66
const x = await ipcRenderer . invoke ( 'providerRequest' , args )
67
+ const jsonErrorInString = extractJSONAfterError ( `${ x } ` )
68
+ if ( jsonErrorInString !== null ) {
69
+ throw jsonErrorInString
70
+ }
71
+
47
72
if (
48
73
x !== null &&
49
74
x !== 'undefined' &&
You can’t perform that action at this time.
0 commit comments