Skip to content

Commit 9b20356

Browse files
authored
[Fix] Network add in portfolio swap (#1153)
* fix network add in portfolio swap * run prettier
1 parent 7a9c4f7 commit 9b20356

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/backend/proxy/providerPreload.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,33 @@ const listenToRendererCalls = (
4242
})
4343
}
4444

45+
function extractJSONAfterError(input: string): object | null {
46+
try {
47+
// Match the pattern where "error=" precedes a JSON string
48+
const errorPattern = /error=(\{[^{}]*\})/
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+
4565
const provRequest = async (args: RequestArguments) => {
4666
const x = await ipcRenderer.invoke('providerRequest', args)
67+
const jsonErrorInString = extractJSONAfterError(`${x}`)
68+
if (jsonErrorInString !== null) {
69+
throw jsonErrorInString
70+
}
71+
4772
if (
4873
x !== null &&
4974
x !== 'undefined' &&

0 commit comments

Comments
 (0)