Remote datasets: cap fetch body size

This commit is contained in:
2026-06-11 19:21:51 +03:00
parent 983c052f3b
commit fe2b039698
6 changed files with 83 additions and 8 deletions
@@ -32,6 +32,13 @@ describe('remoteFetchErrorMessage', () => {
expect(msg).not.toMatch(/inline/i);
});
test('a too-large body names the size limit and a real fix, not the inline fallback', () => {
const msg = remoteFetchErrorMessage(new RemoteFetchError('too-large', 'x'));
expect(msg).toMatch(/too large/i);
expect(msg).toMatch(/MB/);
expect(msg).not.toMatch(/inline/i);
});
test('an unknown error still produces a sensible fallback message', () => {
expect(remoteFetchErrorMessage(new Error('boom'))).toMatch(/couldn't fetch this url/i);
});
+5 -1
View File
@@ -10,7 +10,7 @@
* create/edit form can fall back to pasting inline; Refresh can only retry.
*/
import { RemoteFetchError } from '../infrastructure/remote-data';
import { MAX_REMOTE_BYTES, RemoteFetchError } from '../infrastructure/remote-data';
/** Where the error surfaces, which decides the recovery the copy points at. */
export type FetchRecovery = 'inline' | 'retry';
@@ -45,6 +45,10 @@ export function remoteFetchErrorMessage(err: unknown, recovery: FetchRecovery =
return `This URL returned no data. Make sure it points directly at a data file. ${next}`;
case 'timeout':
return `This URL took too long to respond. ${next}`;
case 'too-large':
// Neither inline-paste nor a retry helps an oversized file, so this points
// at the only real fix instead of the shared next step.
return `This file is too large to store as a dataset (over ${Math.round(MAX_REMOTE_BYTES / (1024 * 1024))} MB). Use a smaller file, or pre-aggregate the data before loading it.`;
}
}
return `Couldn't fetch this URL. ${next}`;