Skip to content

Commit

Permalink
fix: xml2js parse issues (events package required)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamNowotny committed Aug 28, 2024
1 parent 29acaf7 commit 6eaed68
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 8 deletions.
131 changes: 131 additions & 0 deletions package-lock.json

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

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
},
"dependencies": {
"bootstrap": "^5.3.3",
"events": "^3.3.0",
"font-awesome": "4.7.0",
"globals": "15.9.0",
"react-bootstrap": "^2.10.4",
Expand All @@ -47,12 +48,14 @@
"@types/react": "^18.3.4",
"@types/react-dom": "^18.3.0",
"@types/rx": "^4.1.4",
"@types/xml2js": "^0.4.14",
"@vitejs/plugin-react": "^4.3.1",
"eslint": "^9.9.1",
"eslint-plugin-react": "^7.35.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"rollup-plugin-copy": "^3.5.0",
"stream-browserify": "^3.0.0",
"typescript": "^5.5.4",
"typescript-eslint": "^8.2.0",
"vite": "^5.4.2",
Expand Down
15 changes: 7 additions & 8 deletions src/service-worker/request.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logger from 'common/logger';
import { parseString } from 'xml2js';
import * as xml2js from 'xml2js';
import errors from './requestErrors';

interface RequestOptions {
Expand Down Expand Up @@ -85,12 +85,11 @@ function createRequest(options: RequestOptions) {
}

async function parseXml(response: Response) {
return response.text().then(text => {
let result;
parseString(text, (err, json) => {
if (err) throw err;
result = json;
});
const text = await response.text();
try {
const result = await xml2js.parseStringPromise(text);
return result;
});
} catch (error: any) {
throw new Error(`XML parse error: ${error?.message}`);
}
}
5 changes: 5 additions & 0 deletions vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import { defineConfig } from 'vitest/config';

export default defineConfig({
base: './',
resolve: {
alias: {
stream: 'stream-browserify',
},
},
plugins: [
react(),
copy({
Expand Down

0 comments on commit 6eaed68

Please sign in to comment.