diff --git a/package.json b/package.json index a503746..2637a4a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "flibusta", - "version": "0.4.0", + "version": "0.4.1", "author": "ynhhoJ", "description": "Unofficial Flibusta API based on website search engine. If you like to read books - buy", "license": "MIT", diff --git a/src/api/getCoverByBookId.ts b/src/api/getCoverByBookId.ts index 88f2a1d..380057a 100644 --- a/src/api/getCoverByBookId.ts +++ b/src/api/getCoverByBookId.ts @@ -19,7 +19,9 @@ class GetCoverByBookId { private async fetchImageByTypeUrl(url: string): Promise> { return this.axiosInstance.get(url, {}) .then((response) => response.data) - .catch((error) => error); + .catch((error) => { + throw error; + }); } private async fetchCoverByUrl(id: number): Promise> { @@ -27,14 +29,16 @@ class GetCoverByBookId { const yAsString = idAsString.slice(4); const y = Number.parseInt(yAsString, 10); const jpgImageUrl = GetCoverByBookId.generateCoverUrl(id, y, 'jpg'); - const jpgImage = await this.fetchImageByTypeUrl(jpgImageUrl); + // eslint-disable-next-line unicorn/no-useless-undefined + const jpgImage = await this.fetchImageByTypeUrl(jpgImageUrl).catch(() => undefined); if (!isNil(jpgImage)) { return jpgImage; } const pngImageUrl = GetCoverByBookId.generateCoverUrl(id, y, 'png'); - const pngImage = await this.fetchImageByTypeUrl(pngImageUrl); + // eslint-disable-next-line unicorn/no-useless-undefined + const pngImage = await this.fetchImageByTypeUrl(pngImageUrl).catch(() => undefined); if (!isNil(pngImage)) { return pngImage; diff --git a/src/flibustaApiHelper.ts b/src/flibustaApiHelper.ts index b8a99dc..d3a066d 100644 --- a/src/flibustaApiHelper.ts +++ b/src/flibustaApiHelper.ts @@ -65,7 +65,9 @@ abstract class FlibustaAPIHelper extends FlibustaOpdsApiHelper { public async getFlibustaHTMLPage(url: string): Promise { return this.axiosInstance.get(url) .then((response) => parse(response.data).querySelector('#main')) - .catch((error) => error); + .catch((error) => { + throw error; + }); } public getInformationOfBookOrAuthor(node: HTMLElement): Author; diff --git a/src/flibustaOpdsApiHelper.ts b/src/flibustaOpdsApiHelper.ts index 8730e25..1df75ae 100644 --- a/src/flibustaOpdsApiHelper.ts +++ b/src/flibustaOpdsApiHelper.ts @@ -141,7 +141,9 @@ class FlibustaOpdsApiHelper { const parser = new XMLParser(parsingOptions); return parser.parse(response.data); - }).catch((error) => error); + }).catch((error) => { + throw error; + }); } } diff --git a/tests/api/getCoverByBookId.ts b/tests/api/getCoverByBookId.ts index 679ff27..f14fb10 100644 --- a/tests/api/getCoverByBookId.ts +++ b/tests/api/getCoverByBookId.ts @@ -28,10 +28,11 @@ describe('GetCoverBookById', () => { expect(coverByBookId).to.satisfy((cover: File) => !isNil(cover)); }); - it('should return axios error', async () => { - const coverByBookId = await getCoverByBookIdApi.getCoverByBookId(Number.POSITIVE_INFINITY); + it('should return undefined error', async () => { + const coverByBookId = await getCoverByBookIdApi + .getCoverByBookId(Number.POSITIVE_INFINITY); - expect(axios.isAxiosError(coverByBookId)).to.be.equal(true); + expect(isNil(coverByBookId)).to.be.equal(true); }); }); }); diff --git a/tests/flibustaApiHelper.ts b/tests/flibustaApiHelper.ts index c604a46..4675489 100644 --- a/tests/flibustaApiHelper.ts +++ b/tests/flibustaApiHelper.ts @@ -59,13 +59,10 @@ describe('FlibustaAPIHelper', () => { it('should return axios error when flibusta html page is wrong', async () => { const url = 'booksed'; - const flibustaHTMLPage = await flibustaApiHelper.getFlibustaHTMLPage(url); - - if (isNil(flibustaHTMLPage)) { - return; - } - expect(axios.isAxiosError(flibustaHTMLPage)).to.be.equal(true); + await flibustaApiHelper.getFlibustaHTMLPage(url).catch((error) => { + expect(axios.isAxiosError(error)).to.be.equal(true); + }); }); }); diff --git a/tests/index.ts b/tests/index.ts index 694ecb5..9591fff 100644 --- a/tests/index.ts +++ b/tests/index.ts @@ -394,9 +394,9 @@ describe('FlibustaAPI', () => { }); it('should return axios error', async () => { - const coverByBookId = await flibustaApi.getCoverByBookId(Number.POSITIVE_INFINITY); - - expect(axios.isAxiosError(coverByBookId)).to.be.equal(true); + await flibustaApi.getCoverByBookId(Number.POSITIVE_INFINITY).catch((error) => { + expect(axios.isAxiosError(error)).to.be.equal(true); + }); }); }); });