1
0
Fork 0
mirror of synced 2024-09-16 09:17:40 +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,10 +20,17 @@ export async function processInputBBReferences(
} }
for (const id of result) { for (const id of result) {
try {
const user = await cache.user.getUser(id) const user = await cache.user.getUser(id)
if (!user) { if (!user) {
throw new InvalidBBRefError(id, FieldSubtype.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 break
default: default:

View file

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