Skip to content

Commit 88a2e4a

Browse files
authored
fix: improved error description of proxy size limits (#14016)
**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** <img width="798" height="171" alt="1MB_now" src="https://github.com/user-attachments/assets/07b00cd3-ce37-4049-8674-2f3dcb916ab5" /> **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. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## 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. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 0bedaaa commit 88a2e4a

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

packages/common/nbstore/src/impls/cloud/blob.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ export class CloudBlobStorage extends BlobStorageBase {
116116
throw new OverSizeError(this.humanReadableBlobSizeLimitCache);
117117
}
118118
if (userFriendlyError.is('CONTENT_TOO_LARGE')) {
119-
throw new OverSizeError(this.humanReadableBlobSizeLimitCache);
119+
throw new OverSizeError(
120+
null,
121+
'Upload stopped by network proxy: file size exceeds the set limit.'
122+
);
120123
}
121124
throw err;
122125
}
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
export class OverSizeError extends Error {
2-
constructor(limit: string | null) {
3-
const formattedLimit = limit ? `${limit} ` : '';
4-
super(`File size exceeds the ${formattedLimit}limit.`);
2+
constructor(limit: string | null, message?: string) {
3+
if (message) {
4+
super(message);
5+
} else {
6+
const formattedLimit = limit ? `${limit} ` : '';
7+
super(`File size exceeds the ${formattedLimit}limit.`);
8+
}
59
}
610
}

0 commit comments

Comments
 (0)