diff --git a/src/subsonic.ts b/src/subsonic.ts index 31f8272..0823f57 100644 --- a/src/subsonic.ts +++ b/src/subsonic.ts @@ -400,6 +400,8 @@ export class Subsonic implements MusicService { "User-Agent": USER_AGENT, }, ...config, + }).catch(e => { + throw `Subsonic failed with: ${e}`; }) .then((response) => { if (response.status != 200 && response.status != 206) { diff --git a/tests/subsonic.test.ts b/tests/subsonic.test.ts index 78f1631..58f91df 100644 --- a/tests/subsonic.test.ts +++ b/tests/subsonic.test.ts @@ -2756,11 +2756,15 @@ describe("Subsonic", () => { }); describe("navidrome returns something other than a 200", () => { - it("should return the content", async () => { + it("should fail", async () => { const trackId = "track123"; const streamResponse = { status: 400, + headers: { + 'content-type': 'text/html', + 'content-length': '33' + } }; mockGET @@ -2783,6 +2787,31 @@ describe("Subsonic", () => { ).rejects.toEqual(`Subsonic failed with a 400 status`); }); }); + + describe("io exception occurs", () => { + it("should fail", async () => { + const trackId = "track123"; + + mockGET + .mockImplementationOnce(() => Promise.resolve(ok(PING_OK))) + .mockImplementationOnce(() => + Promise.resolve(ok(getSongJson(track))) + ) + .mockImplementationOnce(() => + Promise.resolve(ok(getAlbumJson(artist, album, []))) + ) + .mockImplementationOnce(() => Promise.reject("IO error occured")); + + const musicLibrary = await navidrome + .generateToken({ username, password }) + .then((it) => it as AuthSuccess) + .then((it) => navidrome.login(it.authToken)); + + return expect( + musicLibrary.stream({ trackId, range: undefined }) + ).rejects.toEqual(`Subsonic failed with: IO error occured`); + }); + }); }); describe("with range specified", () => {