Skip to content

Commit

Permalink
wrap fetch error
Browse files Browse the repository at this point in the history
  • Loading branch information
xkopenreview committed Sep 27, 2024
1 parent ce3a399 commit a24f287
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions packages/client/src/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -869,20 +869,25 @@ export default class Tools {
static async extractAbstract(url) {
const metaExtractionUrl = 'https://meta-extraction-wivlbyt6ga-uc.a.run.app/metadata';
const queryString = generateQueryString({ url });
const result = await fetch(`${metaExtractionUrl}?${queryString}`, {
method: 'GET',
});
try {
const result = await fetch(`${metaExtractionUrl}?${queryString}`, {
method: 'GET',
});

if (result.status === 200) {
return result.json();
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) ? JSON.stringify(await result.json()) : await result.text(),
status: result.status || 500
});
} catch (error) {
throw new OpenReviewError({
name: 'ExtractAbstractError',
message: error,
});
}

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

}
}

0 comments on commit a24f287

Please sign in to comment.