-
Notifications
You must be signed in to change notification settings - Fork 399
feat/dataSync #494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat/dataSync #494
Changes from all commits
dad9aca
1679c35
a8d0d73
cd73f80
9c94118
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -143,6 +143,29 @@ export class PubNubAPIError extends Error { | |
| ) { | ||
| errorData = errorResponse; | ||
| status = errorResponse.status; | ||
| } else if ( | ||
| 'errors' in errorResponse && | ||
| Array.isArray(errorResponse.errors) && | ||
| errorResponse.errors.length > 0 | ||
| ) { | ||
| // Handle DataSync-style structured error responses: | ||
| // { errors: [{ errorCode: "SYN-0008", message: "...", path: "/id" }] } | ||
| errorData = errorResponse; | ||
|
|
||
| const errors = errorResponse.errors as Array<{ | ||
| errorCode?: string; | ||
| message?: string; | ||
| path?: string; | ||
| }>; | ||
|
|
||
| message = errors | ||
| .map((e) => { | ||
| const parts: string[] = []; | ||
| if (e.errorCode) parts.push(e.errorCode); | ||
| if (e.message) parts.push(e.message); | ||
| return parts.join(': '); | ||
| }) | ||
| .join('; '); | ||
| } else errorData = errorResponse; | ||
|
Comment on lines
+146
to
169
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle edge case where error items lack both If all items in the Consider filtering out empty results: Proposed fix message = errors
.map((e) => {
const parts: string[] = [];
if (e.errorCode) parts.push(e.errorCode);
if (e.message) parts.push(e.message);
return parts.join(': ');
})
+ .filter((s) => s.length > 0)
.join('; ');
+
+ if (!message) message = 'Unknown error';🤖 Prompt for AI Agents |
||
|
|
||
| if ('error' in errorResponse && errorResponse.error instanceof Error) errorData = errorResponse.error; | ||
|
|
@@ -229,6 +252,35 @@ export class PubNubAPIError extends Error { | |
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Format a user-facing error message for this API error. | ||
| * | ||
| * When the error contains structured details extracted from the service response | ||
| * (e.g., DataSync `errors` array), those details are included in the message. | ||
| * Otherwise, falls back to a generic description. | ||
| * | ||
| * @param operation - Request operation during which error happened. | ||
| * | ||
| * @returns Formatted error message string. | ||
| */ | ||
| public toFormattedMessage(operation: RequestOperation): string { | ||
| const fallback = 'REST API request processing error, check status for details'; | ||
|
|
||
| // When errorData contains a structured `errors` array, `this.message` was already | ||
| // constructed from it in `createFromServiceResponse` — prefer it over the generic fallback. | ||
| if ( | ||
| this.errorData && | ||
| typeof this.errorData === 'object' && | ||
| !('name' in this.errorData && 'message' in this.errorData && 'stack' in this.errorData) && | ||
| 'errors' in this.errorData && | ||
| Array.isArray((this.errorData as Record<string, unknown>).errors) | ||
| ) { | ||
| return `${operation}: ${this.message}`; | ||
| } | ||
|
|
||
| return fallback; | ||
| } | ||
|
|
||
| /** | ||
| * Convert API error object to PubNub client error object. | ||
| * | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: pubnub/javascript
Length of output: 1212
Signature calculation must include PUT request bodies to prevent authentication failures.
The
PUTenum addition is correct, but the signature middleware atsrc/transport/middleware.ts:69-80only includes request body in signature calculation forPOSTandPATCHmethods. PUT requests with bodies will have their body excluded from the signature input, causing authentication validation failures.Update the condition to include
TransportMethod.PUT:🤖 Prompt for AI Agents