add IdentifiableError.isRetryable to ensure that Identifiable Errors can still terminate a batch process

This commit is contained in:
Hazelnoot 2025-02-03 15:03:42 -05:00
parent 4a86ab6857
commit 3391c2414b
3 changed files with 16 additions and 2 deletions

View file

@ -520,7 +520,7 @@ export class DriveService {
// If usage limit exceeded // If usage limit exceeded
if (driveCapacity < usage + info.size) { if (driveCapacity < usage + info.size) {
if (isLocalUser) { if (isLocalUser) {
throw new IdentifiableError('c6244ed2-a39a-4e1c-bf93-f0fbd7764fa6', 'No free space.'); throw new IdentifiableError('c6244ed2-a39a-4e1c-bf93-f0fbd7764fa6', 'No free space.', true);
} }
await this.expireOldFile(await this.usersRepository.findOneByOrFail({ id: user.id }) as MiRemoteUser, driveCapacity - info.size); await this.expireOldFile(await this.usersRepository.findOneByOrFail({ id: user.id }) as MiRemoteUser, driveCapacity - info.size);
} }

View file

@ -10,9 +10,15 @@ export class IdentifiableError extends Error {
public message: string; public message: string;
public id: string; public id: string;
constructor(id: string, message?: string) { /**
* Indicates that this is a temporary error that may be cleared by retrying
*/
public readonly isRetryable: boolean;
constructor(id: string, message?: string, isRetryable = false) {
super(message); super(message);
this.message = message ?? ''; this.message = message ?? '';
this.id = id; this.id = id;
this.isRetryable = isRetryable;
} }
} }

View file

@ -248,6 +248,14 @@ export class InboxProcessorService implements OnApplicationShutdown {
return `skip: permanent error ${e.statusCode}`; return `skip: permanent error ${e.statusCode}`;
} }
if (e instanceof IdentifiableError && !e.isRetryable) {
if (e.message) {
return `skip: permanent error ${e.id}: ${e.message}`;
} else {
return `skip: permanent error ${e.id}`;
}
}
throw e; throw e;
} }
return 'ok'; return 'ok';