mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-21 17:33:29 +01:00
Handling failure to fetch images explicitly and returning 500
This commit is contained in:
@@ -139,10 +139,9 @@ function server(
|
|||||||
.login(authToken)
|
.login(authToken)
|
||||||
.then((it) =>
|
.then((it) =>
|
||||||
it.scrobble(id).then((scrobbleSuccess) => {
|
it.scrobble(id).then((scrobbleSuccess) => {
|
||||||
if(scrobbleSuccess)
|
if (scrobbleSuccess) logger.info(`Scrobbled ${id}`);
|
||||||
logger.info(`Scrobbled ${id}`)
|
else logger.warn(`Failed to scrobble ${id}....`);
|
||||||
else
|
|
||||||
logger.warn(`Failed to scrobble ${id}....`)
|
|
||||||
return it;
|
return it;
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@@ -182,6 +181,13 @@ function server(
|
|||||||
} else {
|
} else {
|
||||||
res.status(404).send();
|
res.status(404).send();
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.catch((e: Error) => {
|
||||||
|
logger.error(
|
||||||
|
`Failed fetching image ${type}/${id}/size/${size}: ${e.message}`,
|
||||||
|
e
|
||||||
|
);
|
||||||
|
res.status(500).send();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -553,7 +553,7 @@ describe("server", () => {
|
|||||||
|
|
||||||
describe("when there is a valid access token", () => {
|
describe("when there is a valid access token", () => {
|
||||||
describe("some invalid art type", () => {
|
describe("some invalid art type", () => {
|
||||||
it("should return the image and a 200", async () => {
|
it("should return a 400", async () => {
|
||||||
const res = await request(server)
|
const res = await request(server)
|
||||||
.get(
|
.get(
|
||||||
`/foo/${albumId}/art/size/180?${BONOB_ACCESS_TOKEN_HEADER}=${accessToken}`
|
`/foo/${albumId}/art/size/180?${BONOB_ACCESS_TOKEN_HEADER}=${accessToken}`
|
||||||
@@ -605,7 +605,23 @@ describe("server", () => {
|
|||||||
|
|
||||||
expect(res.status).toEqual(404);
|
expect(res.status).toEqual(404);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("when there is an error", () => {
|
||||||
|
it("should return a 500", async () => {
|
||||||
|
musicService.login.mockResolvedValue(musicLibrary);
|
||||||
|
|
||||||
|
musicLibrary.coverArt.mockRejectedValue("Boom")
|
||||||
|
|
||||||
|
const res = await request(server)
|
||||||
|
.get(
|
||||||
|
`/artist/${albumId}/art/size/180?${BONOB_ACCESS_TOKEN_HEADER}=${accessToken}`
|
||||||
|
)
|
||||||
|
.set(BONOB_ACCESS_TOKEN_HEADER, accessToken);
|
||||||
|
|
||||||
|
expect(res.status).toEqual(500);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("album art", () => {
|
describe("album art", () => {
|
||||||
@@ -648,6 +664,21 @@ describe("server", () => {
|
|||||||
expect(res.status).toEqual(404);
|
expect(res.status).toEqual(404);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("when there is an error", () => {
|
||||||
|
it("should return a 500", async () => {
|
||||||
|
musicService.login.mockResolvedValue(musicLibrary);
|
||||||
|
musicLibrary.coverArt.mockRejectedValue("Boooooom")
|
||||||
|
|
||||||
|
const res = await request(server)
|
||||||
|
.get(
|
||||||
|
`/album/${albumId}/art/size/180?${BONOB_ACCESS_TOKEN_HEADER}=${accessToken}`
|
||||||
|
)
|
||||||
|
.set(BONOB_ACCESS_TOKEN_HEADER, accessToken);
|
||||||
|
|
||||||
|
expect(res.status).toEqual(500);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user