Skip to content

Commit 7e3af95

Browse files
committed
Adds interface for configuration
1 parent 4f64e97 commit 7e3af95

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

dist/index.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,26 @@ import ExtendableError from 'extendable-error';
33

44
const isString = d => Object.prototype.toString.call(d) === '[object String]';
55
const isObject = d => Object.prototype.toString.call(d) === '[object Object]';
6+
interface ErrorConfig {
7+
message: string;
8+
time_thrown: any;
9+
data: any,
10+
options: any,
11+
}
12+
613
class ApolloError extends ExtendableError {
7-
name: any;
8-
message: any;
14+
name: string;
15+
message: string;
916
time_thrown: any;
1017
data: any;
1118
path: any;
1219
locations: any;
1320
_showLocations: any;
14-
constructor (name, {
15-
message,
16-
time_thrown = (new Date()).toISOString(),
17-
data = {},
18-
options = {},
19-
}) {
20-
const t = (arguments[2] && arguments[2].time_thrown) || time_thrown;
21-
const d = ((arguments[2] && arguments[2].data) || {})
22-
const m = (arguments[2] && arguments[2].message) || message;
23-
const opts = ((arguments[2] && arguments[2].options) || {})
21+
constructor (name, config: ErrorConfig) {
22+
const t = (config && config.time_thrown) || (new Date()).toISOString();
23+
const d = (config && config.data || {})
24+
const m = (config && config.message) || '';
25+
const opts = ((config && config.options) || {})
2426

2527
super(m);
2628

@@ -53,7 +55,8 @@ class ApolloError extends ExtendableError {
5355

5456
export const isInstance = e => e instanceof ApolloError;
5557

56-
export const createError = (name, config) => {
58+
export const createError = (name, config: ErrorConfig) => {
59+
console.log('config', config);
5760
assert(isObject(config), 'createError requires a config object as the second parameter');
5861
assert(isString(config.message), 'createError requires a "message" property on the config object passed as the second parameter');
5962
const e = ApolloError.bind(null, name, config);

0 commit comments

Comments
 (0)