@dvsa/appdev-api-common 0.8.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/http/index.d.ts CHANGED
@@ -1,6 +1,9 @@
1
+ type HTTPErrorResponse = Partial<Omit<Response, "body"> & {
2
+ body: unknown;
3
+ }>;
1
4
  export declare class HTTPError extends Error {
2
- response: Response;
3
- constructor(message: string, response: Response);
5
+ response: HTTPErrorResponse;
6
+ constructor(message: string, response: HTTPErrorResponse);
4
7
  }
5
8
  export declare class HTTP {
6
9
  /**
@@ -34,3 +37,4 @@ export declare class HTTP {
34
37
  */
35
38
  static delete(url: string, options?: RequestInit): Promise<Response>;
36
39
  }
40
+ export {};
package/http/index.js CHANGED
@@ -22,7 +22,10 @@ class HTTP {
22
22
  static async get(url, options) {
23
23
  const response = await fetch(url, { method: "GET", ...options });
24
24
  if (!response.ok) {
25
- throw new HTTPError(`HTTP GET request failed with status ${response.status}`, response);
25
+ throw new HTTPError(`HTTP GET request failed with status ${response.status}`, {
26
+ ...response,
27
+ body: await response.json(),
28
+ });
26
29
  }
27
30
  return response;
28
31
  }
@@ -41,7 +44,10 @@ class HTTP {
41
44
  ...options,
42
45
  });
43
46
  if (!response.ok) {
44
- throw new HTTPError(`HTTP POST request failed with status ${response.status}`, response);
47
+ throw new HTTPError(`HTTP POST request failed with status ${response.status}`, {
48
+ ...response,
49
+ body: await response.json(),
50
+ });
45
51
  }
46
52
  return response;
47
53
  }
@@ -60,7 +66,10 @@ class HTTP {
60
66
  ...options,
61
67
  });
62
68
  if (!response.ok) {
63
- throw new HTTPError(`HTTP PUT request failed with status ${response.status}`, response);
69
+ throw new HTTPError(`HTTP PUT request failed with status ${response.status}`, {
70
+ ...response,
71
+ body: await response.json(),
72
+ });
64
73
  }
65
74
  return response;
66
75
  }
@@ -73,7 +82,10 @@ class HTTP {
73
82
  static async delete(url, options) {
74
83
  const response = await fetch(url, { method: "DELETE", ...options });
75
84
  if (!response.ok) {
76
- throw new HTTPError(`HTTP DELETE request failed with status ${response.status}`, response);
85
+ throw new HTTPError(`HTTP DELETE request failed with status ${response.status}`, {
86
+ ...response,
87
+ body: await response.json(),
88
+ });
77
89
  }
78
90
  return response;
79
91
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dvsa/appdev-api-common",
3
- "version": "0.8.1",
3
+ "version": "0.9.0",
4
4
  "keywords": ["dvsa", "nodejs", "typescript"],
5
5
  "author": "DVSA",
6
6
  "description": "Utils library for common API functionality",