From 88a2e4aa4babe1380e7cddd7e14dc6dc84452d0e Mon Sep 17 00:00:00 2001 From: Daniel Dybing Date: Thu, 27 Nov 2025 05:06:07 +0100 Subject: [PATCH] fix: improved error description of proxy size limits (#14016) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Summary:** This PR improves the user feedback when encountering an HTTP 413 (_CONTENT_TOO_LARGE)_ error caused by a file size limit in the proxy / ingress controller in a self-hosted environment. **Example scenario:** A self-hosted environment serves AFFiNE through an nginx proxy, and the `client_max_body_size` variable in the configuration file is set to a smaller size (e.g. 1MB) than AFFiNE's own file size limit (typically 100MB). Previously, the user would get an error saying the file is larger than 100MB regardless of file size, as all of these cases resulted in the same internal error. With this fix, the _CONTENT_TOO_LARGE_ error is now handled separately and gives better feedback to the user that the failing upload is caused by a fault in the proxy configuration. **Screenshot of new error message** 1MB_now **Affected files:** 1. packages/common/nbstore/src/storage/errors/over-size.ts 2. packages/common/nbstore/src/impls/cloud/blob.ts I'm open to any suggestions in terms of the wording used in the message to the user. The fix has been tested with an nginx proxy. ## Summary by CodeRabbit * **Bug Fixes** * Improved user-facing error messages for file upload failures. When an upload exceeds the file size limit, users now receive a clearer message indicating that the upload was stopped by the network proxy due to the size restriction, providing better understanding of why the upload was rejected. ✏️ Tip: You can customize this high-level summary in your review settings. --- packages/common/nbstore/src/impls/cloud/blob.ts | 5 ++++- .../common/nbstore/src/storage/errors/over-size.ts | 10 +++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/common/nbstore/src/impls/cloud/blob.ts b/packages/common/nbstore/src/impls/cloud/blob.ts index cec0a5c9f6..c317f11161 100644 --- a/packages/common/nbstore/src/impls/cloud/blob.ts +++ b/packages/common/nbstore/src/impls/cloud/blob.ts @@ -116,7 +116,10 @@ export class CloudBlobStorage extends BlobStorageBase { throw new OverSizeError(this.humanReadableBlobSizeLimitCache); } if (userFriendlyError.is('CONTENT_TOO_LARGE')) { - throw new OverSizeError(this.humanReadableBlobSizeLimitCache); + throw new OverSizeError( + null, + 'Upload stopped by network proxy: file size exceeds the set limit.' + ); } throw err; } diff --git a/packages/common/nbstore/src/storage/errors/over-size.ts b/packages/common/nbstore/src/storage/errors/over-size.ts index bbedb1a2dd..abf163b3c9 100644 --- a/packages/common/nbstore/src/storage/errors/over-size.ts +++ b/packages/common/nbstore/src/storage/errors/over-size.ts @@ -1,6 +1,10 @@ export class OverSizeError extends Error { - constructor(limit: string | null) { - const formattedLimit = limit ? `${limit} ` : ''; - super(`File size exceeds the ${formattedLimit}limit.`); + constructor(limit: string | null, message?: string) { + if (message) { + super(message); + } else { + const formattedLimit = limit ? `${limit} ` : ''; + super(`File size exceeds the ${formattedLimit}limit.`); + } } }