Skip to content

Commit

Permalink
Merge pull request #46 from openreview/fix/extract-abtract-error-hand…
Browse files Browse the repository at this point in the history
…ling

Fix/extract abstract error handling
  • Loading branch information
xkopenreview committed Apr 11, 2024
2 parents 91ecb2e + 43aa622 commit d89b025
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openreview/client",
"version": "0.0.29",
"version": "0.0.30",
"description": "Node.js client library for OpenReview's academic publishing API",
"main": "src/index.js",
"type": "module",
Expand Down
17 changes: 15 additions & 2 deletions packages/client/src/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { fileURLToPath } from 'url';
import { XMLParser } from 'fast-xml-parser';
import pkg from 'tldjs';
import { generateQueryString } from './helpers.js';
import OpenReviewError from './errors.js';

const { isValid, getDomain } = pkg;

Expand Down Expand Up @@ -879,11 +880,23 @@ export default class Tools {
* @param {string} url - The url from which the abstract and the PDF are to be extracted
* @returns {object} The abstract and the PDF
*/
static extractAbstract(url) {
static async extractAbstract(url) {
const metaExtractionUrl = 'https://meta-extraction-wivlbyt6ga-uc.a.run.app/metadata';
const queryString = generateQueryString({ url });
return fetch(`${metaExtractionUrl}?${queryString}`, {
const result = await fetch(`${metaExtractionUrl}?${queryString}`, {
method: 'GET',
});

if (result.status === 200) {
return result.json();
}

const contentType = result.headers.get('content-type');
throw new OpenReviewError({
name: 'ExtractAbstractError',
message: (contentType && contentType.indexOf('application/json') !== -1) ? await result.json().message : await result.text(),
status: result.status || 500
});

}
}
12 changes: 12 additions & 0 deletions packages/client/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -802,4 +802,16 @@ describe('OpenReview Client', function () {
}
});

it('should try to extract the abstract but get a 404 error', async function () {

try {
await Tools.extractAbstract('https://doi.org/10.1007/978-981-99-1549-1_15');
} catch (error) {
assert.equal(error.name, 'ExtractAbstractError');
assert.match(error.message, /Error: Page not found/);
assert.equal(error.status, 404);
}

});

});
1 change: 1 addition & 0 deletions packages/meta-extraction/test/test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d89b025

Please sign in to comment.