1
0
Fork 0
mirror of synced 2024-07-21 06:05:52 +12:00

Error handling

This commit is contained in:
Adria Navarro 2023-09-15 12:29:57 +02:00
parent b808d76734
commit 60460da4f9
2 changed files with 15 additions and 3 deletions

View file

@ -20,9 +20,16 @@ export async function processInputBBReferences(
}
for (const id of result) {
const user = await cache.user.getUser(id)
if (!user) {
throw new InvalidBBRefError(id, FieldSubtype.USER)
try {
const user = await cache.user.getUser(id)
if (!user) {
throw new InvalidBBRefError(id, FieldSubtype.USER)
}
} catch (err: any) {
if (err != null && err.status === 404 && err.error === "not_found") {
throw new InvalidBBRefError(id, FieldSubtype.USER)
}
throw err
}
}
break

View file

@ -43,6 +43,11 @@ describe("bbReferenceProcessor", () => {
it("throws an error given an invalid id", async () => {
const userId = generator.guid()
mockedCacheGetUser.mockRejectedValue({
status: 404,
error: "not_found",
})
await expect(
processInputBBReferences(userId, FieldSubtype.USER)
).rejects.toThrowError(new InvalidBBRefError(userId, FieldSubtype.USER))