Skip to content

Commit 10aa9f8

Browse files
Merge pull request #753 from gjsjohnmurray/fix-752
fix #752 Better information if API response isn't JSON
2 parents 824296e + ea6d60a commit 10aa9f8

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/api/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,17 @@ export class AtelierAPI {
355355
}
356356

357357
const buffer = await response.buffer();
358-
const data: Atelier.Response = JSON.parse(buffer.toString("utf-8"));
358+
359+
const responseString = buffer.toString("utf-8");
360+
if (!responseString.startsWith("{")) {
361+
outputConsole(["", `Non-JSON response to ${path}`, ...responseString.split("\r\n")]);
362+
throw {
363+
statusCode: 500,
364+
message: `Non-JSON response to ${path} request. View 'ObjectScript' channel on OUTPUT tab of Panel for details.`,
365+
};
366+
}
367+
368+
const data: Atelier.Response = JSON.parse(responseString);
359369

360370
// Decode encoded content
361371
if (data.result && data.result.enc && data.result.content) {

0 commit comments

Comments
 (0)