Better error messages

This commit is contained in:
Konstantin Wohlwend 2024-12-01 01:51:18 -08:00
parent 65b88f786d
commit 513f4cc15d

View File

@ -48,9 +48,9 @@ function createAdapter(options: {
}
async upsert(id: string, payload: AdapterPayload, expiresInSeconds: number): Promise<void> {
if (expiresInSeconds < 0) throw new StackAssertionError(`expiresInSeconds must be non-negative, got ${expiresInSeconds}`);
if (expiresInSeconds > 60 * 60 * 24 * 365 * 100) throw new StackAssertionError(`expiresInSeconds must be less than 100 years, got ${expiresInSeconds}`);
if (!Number.isFinite(expiresInSeconds)) throw new StackAssertionError(`expiresInSeconds must be a finite number, got ${expiresInSeconds}`);
if (expiresInSeconds < 0) throw new StackAssertionError(`expiresInSeconds must be non-negative, got ${expiresInSeconds}`, { expiresInSeconds, model: this.model, id, payload });
if (expiresInSeconds > 60 * 60 * 24 * 365 * 100) throw new StackAssertionError(`expiresInSeconds must be less than 100 years, got ${expiresInSeconds}`, { expiresInSeconds, model: this.model, id, payload });
if (!Number.isFinite(expiresInSeconds)) throw new StackAssertionError(`expiresInSeconds must be a finite number, got ${expiresInSeconds}`, { expiresInSeconds, model: this.model, id, payload });
await niceUpdate(this.model, id, () => ({ payload, expiresAt: new Date(Date.now() + expiresInSeconds * 1000) }));
}