@timeback/caliper 0.2.1-beta.20260331191116 → 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/errors.d.ts CHANGED
@@ -1 +1,144 @@
1
- export { ApiError as CaliperError, ForbiddenError, InputValidationError, NotFoundError, UnauthorizedError, ValidationError } from '@timeback/internal-client-infra';
1
+ /**
2
+ * Error Types
3
+ *
4
+ * Shared types for error helpers.
5
+ */
6
+ /**
7
+ * Validation issue from client-side input validation.
8
+ */
9
+ interface ValidationIssue {
10
+ /** Field path (e.g. "sourcedId", "metadata.email") */
11
+ path: string;
12
+ /** Human-readable error message */
13
+ message: string;
14
+ }
15
+
16
+ /**
17
+ * API Error Classes
18
+ *
19
+ * Base error classes for HTTP API failures.
20
+ * Includes IMS Global error response parsing (OneRoster, QTI, etc.).
21
+ */
22
+
23
+ /**
24
+ * Base error class for all API errors.
25
+ *
26
+ * Provides access to the HTTP status code and raw response body.
27
+ * Includes IMS Global error parsing (minorCodes, details) for
28
+ * IMS-standard APIs like OneRoster and QTI.
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * // Catching and inspecting errors
33
+ * try {
34
+ * await client.users.get('non-existent-id')
35
+ * } catch (error) {
36
+ * if (error instanceof ApiError) {
37
+ * console.log(`Error ${error.statusCode}: ${error.message}`)
38
+ * console.log('Minor codes:', error.minorCodes)
39
+ * console.log('Details:', error.details)
40
+ * }
41
+ * }
42
+ * ```
43
+ */
44
+ declare class ApiError extends Error {
45
+ readonly statusCode?: number | undefined;
46
+ readonly response?: unknown;
47
+ readonly name: string;
48
+ /**
49
+ * Creates a new ApiError.
50
+ *
51
+ * @param message - Human-readable error message
52
+ * @param statusCode - HTTP status code
53
+ * @param response - Raw response body (if available)
54
+ */
55
+ constructor(message: string, statusCode?: number | undefined, response?: unknown);
56
+ /**
57
+ * Minor error codes from IMS Global error response.
58
+ *
59
+ * For IMS-standard APIs (OneRoster, QTI), provides specific error codes
60
+ * like "unknownobject" or "invaliddata".
61
+ *
62
+ * @returns Array of field/value pairs, or empty array if not IMS format
63
+ */
64
+ get minorCodes(): Array<{
65
+ field: string;
66
+ value: string;
67
+ }>;
68
+ /**
69
+ * Additional error details from IMS Global response.
70
+ *
71
+ * May contain field-level validation errors or other structured details.
72
+ *
73
+ * @returns Array of key-value objects, or empty array if not present
74
+ */
75
+ get details(): Array<Record<string, string>>;
76
+ }
77
+ /**
78
+ * Error thrown when authentication fails (HTTP 401).
79
+ *
80
+ * Typically indicates invalid or expired credentials.
81
+ */
82
+ declare class UnauthorizedError extends ApiError {
83
+ readonly name = "UnauthorizedError";
84
+ constructor(message?: string, response?: unknown);
85
+ }
86
+ /**
87
+ * Error thrown when the client lacks permission for the operation (HTTP 403).
88
+ *
89
+ * The credentials are valid, but the client is not authorized for this action.
90
+ */
91
+ declare class ForbiddenError extends ApiError {
92
+ readonly name = "ForbiddenError";
93
+ constructor(message?: string, response?: unknown);
94
+ }
95
+ /**
96
+ * Error thrown when a requested resource is not found (HTTP 404).
97
+ */
98
+ declare class NotFoundError extends ApiError {
99
+ readonly name = "NotFoundError";
100
+ constructor(message?: string, response?: unknown);
101
+ }
102
+ /**
103
+ * Error thrown when request data is invalid (HTTP 422).
104
+ *
105
+ * Check the `details` property for field-level validation errors.
106
+ */
107
+ declare class ValidationError extends ApiError {
108
+ readonly name = "ValidationError";
109
+ constructor(message?: string, response?: unknown);
110
+ }
111
+ /**
112
+ * Validation issue from client-side input validation.
113
+ */
114
+ /**
115
+ * Error thrown when client-side input validation fails.
116
+ *
117
+ * This is thrown **before** making a network request, providing fast feedback
118
+ * with actionable, path-based error messages.
119
+ *
120
+ * Uses statusCode 400 (Bad Request) to distinguish from server-side 422 errors.
121
+ * Formats like IMS errors via `imsx_error_details` so existing error formatters work.
122
+ *
123
+ * @example
124
+ * ```typescript
125
+ * try {
126
+ * await client.users.create({}) // missing required fields
127
+ * } catch (error) {
128
+ * if (error instanceof InputValidationError) {
129
+ * console.log('Invalid input:', error.issues)
130
+ * // [{ path: 'sourcedId', message: 'Required' }]
131
+ * }
132
+ * }
133
+ * ```
134
+ */
135
+ declare class InputValidationError extends ApiError {
136
+ readonly name = "InputValidationError";
137
+ /**
138
+ * The validation issues that caused this error.
139
+ */
140
+ readonly issues: ValidationIssue[];
141
+ constructor(message: string, issues: ValidationIssue[]);
142
+ }
143
+
144
+ export { ApiError as CaliperError, ForbiddenError, InputValidationError, NotFoundError, UnauthorizedError, ValidationError };