npm package diff
Package: @forge/sql
Versions: 2.2.0 - 2.2.1-next.0
File: package/out/utils/__test__/error-handling.test.js
Index: package/out/utils/__test__/error-handling.test.js
===================================================================
--- package/out/utils/__test__/error-handling.test.js
+++ package/out/utils/__test__/error-handling.test.js
@@ -1,7 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const node_fetch_1 = require("node-fetch");
+const errorCodes_1 = require("../../errorCodes");
const errors_1 = require("../../errors");
const error_handling_1 = require("../error-handling");
describe('errorFromResponse', () => {
const traceId = 'trace-id';
@@ -28,40 +29,18 @@
}
catch (error) {
expect(error).toBeInstanceOf(errors_1.ForgeSQLAPIError);
expect(error).toMatchObject({
- status: 400,
- statusText: 'Bad Request',
- traceId,
+ responseDetails: {
+ status: 400,
+ statusText: 'Bad Request',
+ traceId
+ },
code,
- message,
- serverMessage: message
+ message
});
}
});
- it('should include custom message if provided', async () => {
- const customMessage = 'A custom message';
- const mockResponse = new node_fetch_1.Response(JSON.stringify({ code, message }), {
- status: 400,
- statusText: 'Bad Request',
- headers: { 'x-trace-id': traceId }
- });
- try {
- await (0, error_handling_1.checkResponseError)(mockResponse, customMessage);
- throw new Error('Expected error to be thrown');
- }
- catch (error) {
- expect(error).toBeInstanceOf(errors_1.ForgeSQLAPIError);
- expect(error).toMatchObject({
- status: 400,
- statusText: 'Bad Request',
- traceId,
- code,
- message: customMessage,
- serverMessage: message
- });
- }
- });
it('should include context if present in the Forge error', async () => {
const context = { key: 'value' };
const mockResponse = new node_fetch_1.Response(JSON.stringify({ code, message, context }), {
status: 400,
@@ -77,11 +56,13 @@
expect(error).toMatchObject({
code,
message,
context,
- status: 400,
- statusText: 'Bad Request',
- traceId
+ responseDetails: {
+ status: 400,
+ statusText: 'Bad Request',
+ traceId
+ }
});
}
});
it('should include top level additional fields if present in the Forge error', async () => {
@@ -100,11 +81,13 @@
expect(error).toMatchObject({
code,
message,
context: extraFields,
- status: 400,
- statusText: 'Bad Request',
- traceId
+ responseDetails: {
+ status: 400,
+ statusText: 'Bad Request',
+ traceId
+ }
});
}
});
it('should merge context and additional top level fields if both present in the Forge error', async () => {
@@ -124,11 +107,13 @@
expect(error).toMatchObject({
code,
message,
context: { ...context, ...extraFields },
- status: 400,
- statusText: 'Bad Request',
- traceId
+ responseDetails: {
+ status: 400,
+ statusText: 'Bad Request',
+ traceId
+ }
});
}
});
it('should include suggestion if present in the Forge error', async () => {
@@ -146,17 +131,19 @@
expect(error).toMatchObject({
code,
message,
suggestion,
- status: 400,
- statusText: 'Bad Request',
- traceId
+ responseDetails: {
+ status: 400,
+ statusText: 'Bad Request',
+ traceId
+ }
});
}
});
});
- describe('Unknown or not forge errors - ForgeSQLAPIUnknownError', () => {
- it('returns an ForgeSQLAPIUnknownError when no response body', async () => {
+ describe('Handle non forge errors - UNKNOWN_ERROR', () => {
+ it('returns an when no response body', async () => {
const mockResponse = new node_fetch_1.Response(undefined, {
status: 404,
statusText: 'Not Found',
headers: { 'x-trace-id': traceId }
@@ -165,18 +152,23 @@
await (0, error_handling_1.checkResponseError)(mockResponse);
throw new Error('Expected error to be thrown');
}
catch (error) {
- expect(error).toBeInstanceOf(errors_1.ForgeSQLAPIUnknownError);
+ expect(error).toBeInstanceOf(errors_1.ForgeSQLAPIError);
expect(error).toMatchObject({
- code: 'UNKNOWN_ERROR',
- status: 404,
- statusText: 'Not Found',
- traceId
+ code: errorCodes_1.errorCodes.UNKNOWN_ERROR,
+ context: {
+ responseText: ''
+ },
+ responseDetails: {
+ traceId,
+ status: 404,
+ statusText: 'Not Found'
+ }
});
}
});
- it("returns ForgeSQLAPIUnknownError if there is a JSON body that isn't a forge error", async () => {
+ it("returns UNKNOWN_ERROR if there is a JSON body that isn't a forge error", async () => {
const body = JSON.stringify({ not: 'a forge error' });
const mockResponse = new node_fetch_1.Response(body, {
status: 500,
statusText: 'Internal Server Error',
@@ -186,15 +178,19 @@
await (0, error_handling_1.checkResponseError)(mockResponse);
throw new Error('Expected error to be thrown');
}
catch (error) {
- expect(error).toBeInstanceOf(errors_1.ForgeSQLAPIUnknownError);
+ expect(error).toBeInstanceOf(errors_1.ForgeSQLAPIError);
expect(error).toMatchObject({
- code: 'UNKNOWN_ERROR',
- status: 500,
- statusText: 'Internal Server Error',
- responseText: body,
- traceId
+ code: errorCodes_1.errorCodes.UNKNOWN_ERROR,
+ context: {
+ responseText: body
+ },
+ responseDetails: {
+ traceId,
+ status: 500,
+ statusText: 'Internal Server Error'
+ }
});
}
});
});