Repository navigation
feat(sdk): add proper error handling - #15148
Merged
Merged
Conversation
Fixes #14495 The SDK now throws a proper `PayloadSDKError` class on failed API requests instead of either returning undefined or a generic `Error`. Error handling is centralized in the `request()` method, which adds error handling for operations where it was previously missing (like `create`, `update`, `delete`, `find`, etc.). **Changes:** - Added `PayloadSDKError` class with `status`, `errors`, `response`, and `message` properties - Centralized error handling in `request()` - all operations now properly throw on failed responses. Previously, some operations (like `findByID`) just threw a generic Error that did not explain what actually went wrong and some operations (like `create`) did not throw an error at all and simply returned undefined. - Lots of new int tests **Usage:** ```ts import { PayloadSDKError } from '@payloadcms/sdk' try { await sdk.create({ collection: 'posts', data: { ... } }) } catch (err) { if (err instanceof PayloadSDKError) { console.log(err.status) // 400 console.log(err.errors) // [{ name: 'ValidationError', message: '...', data: {...} }] } } ```
This reverts commit 2d9deef.
This reverts commit 524dd03.
Contributor
📦 esbuild Bundle Analysis for payloadThis analysis was generated by esbuild-bundle-analyzer. 🤖
Largest pathsThese visualization shows top 20 largest paths in the bundle.Meta file: packages/next/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_shared.json, Out file: esbuild/exports/shared.js
Meta file: packages/richtext-lexical/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_shared.json, Out file: esbuild/exports/shared_optimized/index.js
DetailsNext to the size is how much the size has increased or decreased compared with the base branch of this PR.
|
…ugs' into feat/sdk-error-2
…ugs' into feat/sdk-error-2
AlessioGr
marked this pull request as ready for review
January 9, 2026 17:08
r1tsuu
previously approved these changes
Jan 9, 2026
r1tsuu
approved these changes
Jan 9, 2026
Contributor
|
🚀 This is included in version v3.71.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #14495
The SDK now throws a proper
PayloadSDKErrorclass on failed API requests instead of either returning undefined or a genericError. Error handling is centralized in therequest()method, which adds error handling for operations where it was previously missing (likecreate,update,delete,find, etc.).Changes:
PayloadSDKErrorclass withstatus,errors,response, andmessagepropertiesrequest()- all operations now properly throw on failed responses. Previously, some operations (likefindByID) just threw a generic Error that did not explain what actually went wrong and some operations (likecreate) did not throw an error at all and simply returned undefined.Usage: