forked from gadicc/node-yahoo-finance2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.ts
52 lines (43 loc) · 1.27 KB
/
errors.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import type { ErrorObject } from "ajv/dist/types";
// Yahoo's servers returned an HTTP 400 for this request.
export class BadRequestError extends Error {
name = "BadRequestError";
}
// Yahoo's servers returned a 'not-ok' status for this request.
// https://developer.mozilla.org/en-US/docs/Web/API/Response/ok
export class HTTPError extends Error {
name = "HTTPError";
}
// A YahooFinance method was called with invalid options.
export class InvalidOptionsError extends Error {
name = "InvalidOptionsError";
}
// An internal method yahooFinanceFetch() was called without this._env set.
export class NoEnvironmentError extends Error {
name = "NoEnvironmentError";
}
export class FailedYahooValidationError extends Error {
name = "FailedYahooValidationError";
result: any;
errors?: null | ErrorObject[];
constructor(
message: string,
{ result, errors }: { result: any; errors?: null | ErrorObject[] }
) {
super(message);
this.result = result;
this.errors = errors;
}
}
// Index necessary to allow things like: const ErrorClass = errors[errorName];
type ErrorsIndex = {
[key: string]: any;
};
const errors: ErrorsIndex = {
BadRequestError,
HTTPError,
InvalidOptionsError,
NoEnvironmentError,
FailedYahooValidationError,
};
export default errors;