Skip to content

Commit f294c17

Browse files
committed
fix: ignore any php warnings from the url shortener service
1 parent ef35c89 commit f294c17

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/main.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,16 @@ if (typeof Yasgui !== "undefined") {
102102
throw new Error(`HTTP error! status: ${response.status}`);
103103
}
104104

105-
const data = await response.json();
105+
// Get response as text first to handle potential PHP warnings
106+
const responseText = await response.text();
107+
108+
// Extract JSON object from response (ignore any PHP warnings/HTML before it)
109+
const jsonMatch = responseText.match(/\{.*\}/s);
110+
if (!jsonMatch) {
111+
throw new Error('No JSON object found in response');
112+
}
113+
114+
const data = JSON.parse(jsonMatch[0]);
106115

107116
if (data.status === 'fail') {
108117
throw new Error(data.message || 'Failed to shorten URL');

0 commit comments

Comments
 (0)