Skip to content

Commit

Permalink
Change Fetch API library due to test failures and improve error message
Browse files Browse the repository at this point in the history
  • Loading branch information
happy5214 committed Apr 19, 2024
1 parent 1d51a38 commit 60ac633
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 5 deletions.
84 changes: 84 additions & 0 deletions 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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
"homepage": "https://github.com/hed-standard/hed-javascript",
"dependencies": {
"buffer": "^6.0.3",
"cross-fetch": "^4.0.0",
"date-and-time": "^0.14.2",
"date-fns": "^2.17.0",
"events": "^3.3.0",
"lodash": "^4.17.21",
"node-fetch": "^3.3.2",
"path": "^0.12.7",
"pluralize": "^8.0.0",
"semver": "^7.3.4",
Expand Down
6 changes: 3 additions & 3 deletions tests/bids.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ describe('BIDS datasets', () => {
generateIssue('remoteSchemaLoadFailed', {
spec: JSON.stringify(new SchemaSpec('ts', '1.0.2', 'badlib')),
error:
'Server responded to https://raw.githubusercontent.com/hed-standard/hed-schemas/main/library_schemas/badlib/hedxml/HED_badlib_1.0.2.xml with status code 404:\n404: Not Found',
'Server responded to https://raw.githubusercontent.com/hed-standard/hed-schemas/main/library_schemas/badlib/hedxml/HED_badlib_1.0.2.xml with status code 404: Not Found',
}),
badDatasetDescriptions[0].file,
),
Expand Down Expand Up @@ -410,7 +410,7 @@ describe('BIDS datasets', () => {
generateIssue('remoteSchemaLoadFailed', {
spec: JSON.stringify(new SchemaSpec('ts', '1.800.2', 'testlib')),
error:
'Server responded to https://raw.githubusercontent.com/hed-standard/hed-schemas/main/library_schemas/testlib/hedxml/HED_testlib_1.800.2.xml with status code 404:\n404: Not Found',
'Server responded to https://raw.githubusercontent.com/hed-standard/hed-schemas/main/library_schemas/testlib/hedxml/HED_testlib_1.800.2.xml with status code 404: Not Found',
}),
badDatasetDescriptions[8].file,
),
Expand All @@ -420,7 +420,7 @@ describe('BIDS datasets', () => {
generateIssue('remoteSchemaLoadFailed', {
spec: JSON.stringify(new SchemaSpec('', '8.828.0', '')),
error:
'Server responded to https://raw.githubusercontent.com/hed-standard/hed-schemas/main/standard_schema/hedxml/HED8.828.0.xml with status code 404:\n404: Not Found',
'Server responded to https://raw.githubusercontent.com/hed-standard/hed-schemas/main/standard_schema/hedxml/HED8.828.0.xml with status code 404: Not Found',
}),
badDatasetDescriptions[9].file,
),
Expand Down
4 changes: 3 additions & 1 deletion utils/files.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import fs from 'fs'

import fetch, { Request } from 'cross-fetch'

/**
* Read a local file.
*
Expand All @@ -24,7 +26,7 @@ export const readHTTPSFile = function (url) {
const myRequest = new Request(url)
return fetch(myRequest).then((response) => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`)
throw new Error(`Server responded to ${url} with status code ${response.status}: ${response.statusText}`)
}
return response.text()
})
Expand Down

0 comments on commit 60ac633

Please sign in to comment.