@shipstatic/types 0.2.0 → 0.2.1
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 +1 -1
- package/dist/index.js +7 -3
- package/package.json +1 -1
- package/src/index.ts +8 -3
package/dist/index.d.ts
CHANGED
|
@@ -152,7 +152,7 @@ export declare class ShipError extends Error {
|
|
|
152
152
|
static validation(message: string, details?: any): ShipError;
|
|
153
153
|
static notFound(resource: string, id?: string): ShipError;
|
|
154
154
|
static rateLimit(message?: string): ShipError;
|
|
155
|
-
static authentication(message?: string): ShipError;
|
|
155
|
+
static authentication(message?: string, details?: any): ShipError;
|
|
156
156
|
static business(message: string, status?: number): ShipError;
|
|
157
157
|
static network(message: string, cause?: Error): ShipError;
|
|
158
158
|
static cancelled(message: string): ShipError;
|
package/dist/index.js
CHANGED
|
@@ -58,11 +58,15 @@ export class ShipError extends Error {
|
|
|
58
58
|
}
|
|
59
59
|
/** Convert to wire format */
|
|
60
60
|
toResponse() {
|
|
61
|
+
// For security, exclude internal details from authentication errors in API responses
|
|
62
|
+
const details = this.type === ErrorType.Authentication && this.details?.internal
|
|
63
|
+
? undefined
|
|
64
|
+
: this.details;
|
|
61
65
|
return {
|
|
62
66
|
error: this.type,
|
|
63
67
|
message: this.message,
|
|
64
68
|
status: this.status,
|
|
65
|
-
details
|
|
69
|
+
details
|
|
66
70
|
};
|
|
67
71
|
}
|
|
68
72
|
/** Create from wire format */
|
|
@@ -80,8 +84,8 @@ export class ShipError extends Error {
|
|
|
80
84
|
static rateLimit(message = "Too many requests") {
|
|
81
85
|
return new ShipError(ErrorType.RateLimit, message, 429);
|
|
82
86
|
}
|
|
83
|
-
static authentication(message = "Authentication required") {
|
|
84
|
-
return new ShipError(ErrorType.Authentication, message, 401);
|
|
87
|
+
static authentication(message = "Authentication required", details) {
|
|
88
|
+
return new ShipError(ErrorType.Authentication, message, 401, details);
|
|
85
89
|
}
|
|
86
90
|
static business(message, status = 400) {
|
|
87
91
|
return new ShipError(ErrorType.Business, message, status);
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -189,11 +189,16 @@ export class ShipError extends Error {
|
|
|
189
189
|
|
|
190
190
|
/** Convert to wire format */
|
|
191
191
|
toResponse(): ErrorResponse {
|
|
192
|
+
// For security, exclude internal details from authentication errors in API responses
|
|
193
|
+
const details = this.type === ErrorType.Authentication && this.details?.internal
|
|
194
|
+
? undefined
|
|
195
|
+
: this.details;
|
|
196
|
+
|
|
192
197
|
return {
|
|
193
198
|
error: this.type,
|
|
194
199
|
message: this.message,
|
|
195
200
|
status: this.status,
|
|
196
|
-
details
|
|
201
|
+
details
|
|
197
202
|
};
|
|
198
203
|
}
|
|
199
204
|
|
|
@@ -216,8 +221,8 @@ export class ShipError extends Error {
|
|
|
216
221
|
return new ShipError(ErrorType.RateLimit, message, 429);
|
|
217
222
|
}
|
|
218
223
|
|
|
219
|
-
static authentication(message: string = "Authentication required"): ShipError {
|
|
220
|
-
return new ShipError(ErrorType.Authentication, message, 401);
|
|
224
|
+
static authentication(message: string = "Authentication required", details?: any): ShipError {
|
|
225
|
+
return new ShipError(ErrorType.Authentication, message, 401, details);
|
|
221
226
|
}
|
|
222
227
|
|
|
223
228
|
|