@hkdigital/lib-core 0.3.8 → 0.3.9

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.
@@ -31,6 +31,15 @@ export class PinoAdapter {
31
31
  stack: current.stack
32
32
  })
33
33
  };
34
+
35
+ // Include HttpError-specific properties
36
+ if (current.status !== undefined) {
37
+ serialized.status = current.status;
38
+ }
39
+ if (current.details !== undefined) {
40
+ serialized.details = current.details;
41
+ }
42
+
34
43
  chain.push(serialized);
35
44
  current = current.cause;
36
45
  isFirst = false;
@@ -1,4 +1,4 @@
1
- import { ResponseError } from '../../errors/index.js';
1
+ import { ResponseError, HttpError } from '../../errors/index.js';
2
2
  import * as expect from '../expect/index.js';
3
3
  import { toURL } from './url.js';
4
4
 
@@ -155,11 +155,35 @@ export async function waitForAndCheckResponse(responsePromise, url) {
155
155
  response = await responsePromise;
156
156
 
157
157
  if (response && false === response.ok) {
158
- // if response.ok is false, it also indicates a network error
159
- throw new Error(`Response failed [response.ok=false]`);
158
+ // Check if this is a network error (status 0) vs HTTP error
159
+ if (response.status === 0) {
160
+ // Network error - treat as before
161
+ throw new Error(`Response failed [response.ok=false]`);
162
+ }
163
+
164
+ // HTTP error - get response body for detailed error information
165
+ const responseBody = await response.text();
166
+ let errorDetails;
167
+
168
+ try {
169
+ // Try to parse as JSON (common for API errors)
170
+ errorDetails = JSON.parse(responseBody);
171
+ } catch {
172
+ // Fallback to plain text
173
+ errorDetails = responseBody;
174
+ }
175
+
176
+ throw new HttpError(
177
+ response.status,
178
+ `HTTP ${response.status}: ${response.statusText}`,
179
+ errorDetails
180
+ );
160
181
  }
161
182
  } catch (e) {
162
- if (e instanceof TypeError || response?.ok === false) {
183
+ if (e instanceof HttpError) {
184
+ // Re-throw HttpError as-is
185
+ throw e;
186
+ } else if (e instanceof TypeError || response?.ok === false) {
163
187
  throw new ResponseError(
164
188
  `A network error occurred for request [${href(url)}]`,
165
189
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hkdigital/lib-core",
3
- "version": "0.3.8",
3
+ "version": "0.3.9",
4
4
  "author": {
5
5
  "name": "HKdigital",
6
6
  "url": "https://hkdigital.nl"