npm package diff
Package: @forge/sql
Versions: 2.2.0-next.2 - 2.2.0-next.3
File: package/out/utils/error-handling.js
Index: package/out/utils/error-handling.js
===================================================================
--- package/out/utils/error-handling.js
+++ package/out/utils/error-handling.js
@@ -0,0 +1,39 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.checkResponseError = exports.isForgeError = void 0;
+const errors_1 = require("../errors");
+function isForgeError(body) {
+ if (typeof body === 'object' && body !== null) {
+ if ('code' in body && 'message' in body) {
+ return true;
+ }
+ }
+ return false;
+}
+exports.isForgeError = isForgeError;
+async function checkResponseError(response, message) {
+ if (response.ok) {
+ return;
+ }
+ const responseText = await response.text();
+ const details = {
+ status: response.status,
+ statusText: response.statusText,
+ traceId: response.headers.get('x-trace-id')
+ };
+ try {
+ const parsedBody = JSON.parse(responseText);
+ if (isForgeError(parsedBody)) {
+ throw new errors_1.ForgeSQLAPIError(details, parsedBody, message);
+ }
+ }
+ catch (error) {
+ if (error instanceof SyntaxError) {
+ }
+ else {
+ throw error;
+ }
+ }
+ throw new errors_1.ForgeSQLAPIUnknownError(details, responseText, message);
+}
+exports.checkResponseError = checkResponseError;