- init fragmenté : lit target/path dans la query (corps en repli) (#1) - erreurs client interrompu / disque plein / fichier partiel absent mappées en 400/507/404 sans webhook d'échec pour les interruptions (#2) - nettoyage des sessions expirées et des .part orphelins sécurisé, log des unhandledRejection (#2) - plafond de sessions porté à 256 pour l'usage multi-fenêtres (#3) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
|
|
import {
|
|
ClientAbortedError,
|
|
InsufficientStorageError,
|
|
PayloadTooLargeError,
|
|
ValidationError,
|
|
} from '../src/errors.js';
|
|
import { normalizeStreamError } from '../src/lib/storage.js';
|
|
|
|
function withCode(code: string): Error {
|
|
return Object.assign(new Error('boom'), { code });
|
|
}
|
|
|
|
describe('normalizeStreamError', () => {
|
|
it('conserve les AppError telles quelles', () => {
|
|
const error = new ValidationError('x');
|
|
expect(normalizeStreamError(error)).toBe(error);
|
|
});
|
|
|
|
it('convertit le dépassement multipart en 413', () => {
|
|
expect(normalizeStreamError(withCode('FST_REQ_FILE_TOO_LARGE'))).toBeInstanceOf(
|
|
PayloadTooLargeError,
|
|
);
|
|
});
|
|
|
|
it.each(['ECONNRESET', 'ECONNABORTED', 'ERR_STREAM_PREMATURE_CLOSE'])(
|
|
'convertit %s (client parti) en ClientAbortedError',
|
|
(code) => {
|
|
expect(normalizeStreamError(withCode(code))).toBeInstanceOf(ClientAbortedError);
|
|
},
|
|
);
|
|
|
|
it('convertit ENOSPC en InsufficientStorageError (507)', () => {
|
|
const result = normalizeStreamError(withCode('ENOSPC'));
|
|
expect(result).toBeInstanceOf(InsufficientStorageError);
|
|
expect((result as InsufficientStorageError).statusCode).toBe(507);
|
|
});
|
|
|
|
it('laisse passer les autres erreurs et enveloppe les valeurs non-Error', () => {
|
|
const other = withCode('EACCES');
|
|
expect(normalizeStreamError(other)).toBe(other);
|
|
expect(normalizeStreamError('texte')).toBeInstanceOf(Error);
|
|
});
|
|
});
|