@shipstatic/types 2.5.0-beta.5 → 2.5.0-beta.6

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/dist/index.d.ts CHANGED
@@ -423,6 +423,18 @@ export declare class ShipError extends Error {
423
423
  static file(message: string, details?: unknown): ShipError;
424
424
  static config(message: string, details?: unknown): ShipError;
425
425
  static api(message: string, status?: number, details?: unknown): ShipError;
426
+ /**
427
+ * The caller is at fault — by HTTP's own definition of a 4xx, or by a type
428
+ * that is client-attributable without ever having a status (`Config`,
429
+ * `File`, raised locally by the SDK).
430
+ *
431
+ * Both arms are load-bearing, because type and status are independent
432
+ * axes. `fromHttpResponse` trusts `body.error` only when it names a
433
+ * server-producible type; a non-OK response without one is status-derived,
434
+ * so a CDN 404 or any intermediary error arrives as `Api` — a server-fault
435
+ * *type* carrying a client *status*. Judging by type alone would report it
436
+ * as a platform failure and bury the server's own message.
437
+ */
426
438
  isClientError(): boolean;
427
439
  isNetworkError(): boolean;
428
440
  isAuthError(): boolean;
package/dist/index.js CHANGED
@@ -101,10 +101,10 @@ const CLIENT_ONLY_ERROR_TYPES = new Set([
101
101
  */
102
102
  const ERROR_CATEGORIES = {
103
103
  /**
104
- * Every 4xx-class type the caller's request or state is at fault, and
105
- * the authored message is safe to surface verbatim. The set is exhaustive
106
- * on purpose: a partial one forces consumers to add a status-range check
107
- * beside every `isClientError()` call for the types it forgot.
104
+ * Client-attributable types. Exhaustive over the 4xx-carrying types, and
105
+ * it must include the statusless ones (`Config`, `File`) those are
106
+ * raised locally by the SDK and have no status for `isClientError`'s
107
+ * second arm to read.
108
108
  */
109
109
  client: new Set([
110
110
  ErrorType.Business,
@@ -317,10 +317,24 @@ export class ShipError extends Error {
317
317
  static api(message, status = 500, details) {
318
318
  return new ShipError(ErrorType.Api, message, status, details);
319
319
  }
320
- // Semantic-category type guards. For specific-type checks, use
320
+ // Semantic-category guards. For specific-type checks, use
321
321
  // `error.type === ErrorType.X` directly or the generic `isType(t)`.
322
+ /**
323
+ * The caller is at fault — by HTTP's own definition of a 4xx, or by a type
324
+ * that is client-attributable without ever having a status (`Config`,
325
+ * `File`, raised locally by the SDK).
326
+ *
327
+ * Both arms are load-bearing, because type and status are independent
328
+ * axes. `fromHttpResponse` trusts `body.error` only when it names a
329
+ * server-producible type; a non-OK response without one is status-derived,
330
+ * so a CDN 404 or any intermediary error arrives as `Api` — a server-fault
331
+ * *type* carrying a client *status*. Judging by type alone would report it
332
+ * as a platform failure and bury the server's own message.
333
+ */
322
334
  isClientError() {
323
- return ERROR_CATEGORIES.client.has(this.type);
335
+ if (ERROR_CATEGORIES.client.has(this.type))
336
+ return true;
337
+ return this.status !== undefined && this.status >= 400 && this.status < 500;
324
338
  }
325
339
  isNetworkError() {
326
340
  return ERROR_CATEGORIES.network.has(this.type);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shipstatic/types",
3
- "version": "2.5.0-beta.5",
3
+ "version": "2.5.0-beta.6",
4
4
  "description": "Shared types for ShipStatic platform",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/index.ts CHANGED
@@ -400,10 +400,10 @@ const CLIENT_ONLY_ERROR_TYPES = new Set<string>([
400
400
  */
401
401
  const ERROR_CATEGORIES = {
402
402
  /**
403
- * Every 4xx-class type the caller's request or state is at fault, and
404
- * the authored message is safe to surface verbatim. The set is exhaustive
405
- * on purpose: a partial one forces consumers to add a status-range check
406
- * beside every `isClientError()` call for the types it forgot.
403
+ * Client-attributable types. Exhaustive over the 4xx-carrying types, and
404
+ * it must include the statusless ones (`Config`, `File`) those are
405
+ * raised locally by the SDK and have no status for `isClientError`'s
406
+ * second arm to read.
407
407
  */
408
408
  client: new Set<ErrorType>([
409
409
  ErrorType.Business,
@@ -655,10 +655,24 @@ export class ShipError extends Error {
655
655
  return new ShipError(ErrorType.Api, message, status, details);
656
656
  }
657
657
 
658
- // Semantic-category type guards. For specific-type checks, use
658
+ // Semantic-category guards. For specific-type checks, use
659
659
  // `error.type === ErrorType.X` directly or the generic `isType(t)`.
660
+
661
+ /**
662
+ * The caller is at fault — by HTTP's own definition of a 4xx, or by a type
663
+ * that is client-attributable without ever having a status (`Config`,
664
+ * `File`, raised locally by the SDK).
665
+ *
666
+ * Both arms are load-bearing, because type and status are independent
667
+ * axes. `fromHttpResponse` trusts `body.error` only when it names a
668
+ * server-producible type; a non-OK response without one is status-derived,
669
+ * so a CDN 404 or any intermediary error arrives as `Api` — a server-fault
670
+ * *type* carrying a client *status*. Judging by type alone would report it
671
+ * as a platform failure and bury the server's own message.
672
+ */
660
673
  isClientError(): boolean {
661
- return ERROR_CATEGORIES.client.has(this.type);
674
+ if (ERROR_CATEGORIES.client.has(this.type)) return true;
675
+ return this.status !== undefined && this.status >= 400 && this.status < 500;
662
676
  }
663
677
 
664
678
  isNetworkError(): boolean {