Skip to content

Commit

Permalink
update error throw logic
Browse files Browse the repository at this point in the history
  • Loading branch information
xkopenreview committed Sep 30, 2024
1 parent d231bf6 commit 34c74be
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions packages/client/src/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -869,26 +869,28 @@ export default class Tools {
static async extractAbstract(url) {
const metaExtractionUrl = 'https://meta-extraction-wivlbyt6ga-uc.a.run.app/metadata';
const queryString = generateQueryString({ url });
let result;

try {
const result = await fetch(`${metaExtractionUrl}?${queryString}`, {
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) ? JSON.stringify(await result.json()) : await result.text(),
status: result.status || 500
});
} catch (error) {
throw new OpenReviewError({
name: 'ExtractAbstractError',
message: error,
});
}

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
});
}
}

0 comments on commit 34c74be

Please sign in to comment.