Skip to content
This repository has been archived by the owner on Mar 29, 2021. It is now read-only.

Commit

Permalink
fix error message parsing in csl file parser
Browse files Browse the repository at this point in the history
  • Loading branch information
dsifford committed Jan 19, 2019
1 parent 81f8619 commit ad41da8
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/js/utils/file.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { __ } from '@wordpress/i18n';
import { parse as parseBibtex } from 'astrocite-bibtex';
import { parse as parseRis } from 'astrocite-ris';

Expand Down Expand Up @@ -45,8 +46,18 @@ export async function parseCSL(file: File): Promise<Style> {
const error = xml.querySelector('parsererror');
const label = xml.querySelector('info title');
const shortTitle = xml.querySelector('info title-short');
if (error || !label || !label.textContent) {
throw new Error(`Error parsing CSL file: ${error}`);
if (error) {
const message = error.querySelector('div');
throw new Error(
message && message.textContent
? message.textContent
: __('Error parsing CSL file.', 'academic-bloggers-toolkit'),
);
}
if (!label || !label.textContent) {
throw new Error(
__('Error parsing CSL file.', 'academic-bloggers-toolkit'),
);
}
// trim away unnecessary whitespace
const value = content
Expand Down

0 comments on commit ad41da8

Please # to comment.