-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support reading dictionary files over http. (#3150)
* Support reading files over http. * Update fileReader.ts * Support detecting dictionary changes.
- Loading branch information
Showing
23 changed files
with
571 additions
and
91 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { FetchUrlError } from './FetchError'; | ||
import { toURL } from './util'; | ||
|
||
const oc = expect.objectContaining; | ||
|
||
describe('FetchError', () => { | ||
test.each` | ||
url | status | message | expected | ||
${'http://google.com'} | ${404} | ${undefined} | ${oc({ code: 'ENOENT', message: 'URL not found.' })} | ||
${'http://google.com'} | ${403} | ${undefined} | ${oc({ code: 'EACCES', message: 'Permission denied.' })} | ||
${'http://google.com'} | ${403} | ${'Not good'} | ${oc({ code: 'EACCES', message: 'Not good' })} | ||
${'http://google.com'} | ${500} | ${''} | ${oc({ code: 'ECONNREFUSED', message: 'Fatal Error' })} | ||
`('create', ({ url, status, message, expected }) => { | ||
url = toURL(url); | ||
const e = FetchUrlError.create(url, status, message); | ||
expect(e).toEqual(expected); | ||
expect(e.url).toBe(url); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export class FetchUrlError extends Error implements NodeJS.ErrnoException { | ||
constructor( | ||
message: string, | ||
readonly code: string | undefined, | ||
readonly status: number | undefined, | ||
readonly url: URL | ||
) { | ||
super(message); | ||
this.name = 'FetchUrlError'; | ||
} | ||
|
||
static create(url: URL, status: number, message?: string): FetchUrlError { | ||
if (status === 404) return new FetchUrlError(message || 'URL not found.', 'ENOENT', status, url); | ||
if (status >= 400 && status < 500) | ||
return new FetchUrlError(message || 'Permission denied.', 'EACCES', status, url); | ||
return new FetchUrlError(message || 'Fatal Error', 'ECONNREFUSED', status, url); | ||
} | ||
} |
Oops, something went wrong.