@shipstatic/types 2.5.0-beta.13 → 2.5.0-beta.14
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.js +18 -2
- package/package.json +1 -1
- package/src/index.ts +20 -2
package/dist/index.js
CHANGED
|
@@ -214,6 +214,14 @@ const ERROR_CATEGORIES = {
|
|
|
214
214
|
* `ErrorType` is automatically picked up.
|
|
215
215
|
*/
|
|
216
216
|
const SERVER_PRODUCIBLE_ERROR_TYPES = new Set(Object.values(ErrorType).filter((t) => !CLIENT_ONLY_ERROR_TYPES.has(t)));
|
|
217
|
+
/**
|
|
218
|
+
* Ceiling on a message adopted from a **non-JSON** error body — a foreign
|
|
219
|
+
* responder's, never this platform's. Generous for the plain-text one-liners
|
|
220
|
+
* intermediaries actually send (`error code: 1015`), far below a document.
|
|
221
|
+
* Our own messages are never measured against it: a JSON body is the API's
|
|
222
|
+
* contract, and truncating a long validation message would be the bug.
|
|
223
|
+
*/
|
|
224
|
+
const MAX_FOREIGN_MESSAGE_LENGTH = 200;
|
|
217
225
|
/**
|
|
218
226
|
* Simple unified error class for both API and SDK
|
|
219
227
|
*/
|
|
@@ -285,9 +293,17 @@ export class ShipError extends Error {
|
|
|
285
293
|
}
|
|
286
294
|
}
|
|
287
295
|
else {
|
|
288
|
-
|
|
289
|
-
|
|
296
|
+
// A non-JSON body did not come from this platform — every API error
|
|
297
|
+
// is `ErrorResponse` JSON — so it is an intermediary's output, and
|
|
298
|
+
// the two kinds it produces need opposite treatment. A CDN's plain
|
|
299
|
+
// `error code: 1015` is the most useful thing there is to say. A
|
|
300
|
+
// proxy's HTML error page is a *document*, not a message: adopting it
|
|
301
|
+
// verbatim made a misconfigured `apiUrl` print 2,059 characters of
|
|
302
|
+
// markup as the error. Trust it only when it reads as a message.
|
|
303
|
+
const text = (await response.text()).trim();
|
|
304
|
+
if (text && !text.startsWith('<') && text.length <= MAX_FOREIGN_MESSAGE_LENGTH) {
|
|
290
305
|
message = text;
|
|
306
|
+
}
|
|
291
307
|
}
|
|
292
308
|
}
|
|
293
309
|
catch {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -702,6 +702,15 @@ const SERVER_PRODUCIBLE_ERROR_TYPES = new Set<string>(
|
|
|
702
702
|
Object.values(ErrorType).filter((t) => !CLIENT_ONLY_ERROR_TYPES.has(t)),
|
|
703
703
|
);
|
|
704
704
|
|
|
705
|
+
/**
|
|
706
|
+
* Ceiling on a message adopted from a **non-JSON** error body — a foreign
|
|
707
|
+
* responder's, never this platform's. Generous for the plain-text one-liners
|
|
708
|
+
* intermediaries actually send (`error code: 1015`), far below a document.
|
|
709
|
+
* Our own messages are never measured against it: a JSON body is the API's
|
|
710
|
+
* contract, and truncating a long validation message would be the bug.
|
|
711
|
+
*/
|
|
712
|
+
const MAX_FOREIGN_MESSAGE_LENGTH = 200;
|
|
713
|
+
|
|
705
714
|
/**
|
|
706
715
|
* Standard error response format used everywhere
|
|
707
716
|
*/
|
|
@@ -788,8 +797,17 @@ export class ShipError extends Error {
|
|
|
788
797
|
}
|
|
789
798
|
}
|
|
790
799
|
} else {
|
|
791
|
-
|
|
792
|
-
|
|
800
|
+
// A non-JSON body did not come from this platform — every API error
|
|
801
|
+
// is `ErrorResponse` JSON — so it is an intermediary's output, and
|
|
802
|
+
// the two kinds it produces need opposite treatment. A CDN's plain
|
|
803
|
+
// `error code: 1015` is the most useful thing there is to say. A
|
|
804
|
+
// proxy's HTML error page is a *document*, not a message: adopting it
|
|
805
|
+
// verbatim made a misconfigured `apiUrl` print 2,059 characters of
|
|
806
|
+
// markup as the error. Trust it only when it reads as a message.
|
|
807
|
+
const text = (await response.text()).trim();
|
|
808
|
+
if (text && !text.startsWith('<') && text.length <= MAX_FOREIGN_MESSAGE_LENGTH) {
|
|
809
|
+
message = text;
|
|
810
|
+
}
|
|
793
811
|
}
|
|
794
812
|
} catch {
|
|
795
813
|
// Body unreadable; fall through to operationName-derived message.
|