mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-21 17:33:29 +01:00
Catch unhandled io errors in subsonic (#75)
This commit is contained in:
@@ -400,6 +400,8 @@ export class Subsonic implements MusicService {
|
|||||||
"User-Agent": USER_AGENT,
|
"User-Agent": USER_AGENT,
|
||||||
},
|
},
|
||||||
...config,
|
...config,
|
||||||
|
}).catch(e => {
|
||||||
|
throw `Subsonic failed with: ${e}`;
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (response.status != 200 && response.status != 206) {
|
if (response.status != 200 && response.status != 206) {
|
||||||
|
|||||||
@@ -2756,11 +2756,15 @@ describe("Subsonic", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("navidrome returns something other than a 200", () => {
|
describe("navidrome returns something other than a 200", () => {
|
||||||
it("should return the content", async () => {
|
it("should fail", async () => {
|
||||||
const trackId = "track123";
|
const trackId = "track123";
|
||||||
|
|
||||||
const streamResponse = {
|
const streamResponse = {
|
||||||
status: 400,
|
status: 400,
|
||||||
|
headers: {
|
||||||
|
'content-type': 'text/html',
|
||||||
|
'content-length': '33'
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
mockGET
|
mockGET
|
||||||
@@ -2783,6 +2787,31 @@ describe("Subsonic", () => {
|
|||||||
).rejects.toEqual(`Subsonic failed with a 400 status`);
|
).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", () => {
|
describe("with range specified", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user