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,10 +20,17 @@ export async function processInputBBReferences(
}
for (const id of result) {
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
default:

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))