Skip to content

Commit

Permalink
* Removes build script from package.json
Browse files Browse the repository at this point in the history
* Adds build script in make file
* Removes un-used modules from package.json
* Changes type of time_thrown and _showLocation
* Gives default type as string to name parameter in constructor and createError
* Removes unsued configurations from tsconfig
  • Loading branch information
lakhansamani committed Sep 22, 2017
1 parent fbac46b commit 5665a6a
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ endif
.FORCE:

all: clean
npm run build
tsc

clean: .FORCE
rimraf npm-debug.log dist
Expand Down
3 changes: 2 additions & 1 deletion dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

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

9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"description": "Machine-readable custom errors for Apollostack's GraphQL server",
"main": "dist/index.js",
"scripts": {
"test": "make test",
"build": "tsc"
"test": "make test"
},
"repository": {
"type": "git",
Expand All @@ -27,8 +26,7 @@
"homepage": "https://github.com/thebigredgeek/apollo-errors#readme",
"dependencies": {
"assert": "^1.4.1",
"extendable-error": "^0.1.5",
"install": "^0.10.1"
"extendable-error": "^0.1.5"
},
"devDependencies": {
"babel-cli": "^6.18.0",
Expand All @@ -41,7 +39,6 @@
"eslint-plugin-babel": "^3.3.0",
"mocha": "^3.1.2",
"rimraf": "^2.5.4",
"typescript": "^2.5.2",
"typings": "^2.1.1"
"typescript": "^2.5.2"
}
}
17 changes: 11 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
import * as assert from 'assert';
import ExtendableError from 'extendable-error';

const isString = d => Object.prototype.toString.call(d) === '[object String]';
const isObject = d => Object.prototype.toString.call(d) === '[object Object]';

interface ErrorConfig {
message: string;
time_thrown: any;
time_thrown: string;
data: any,
options: any,
}

class ApolloError extends ExtendableError {
name: string;
message: string;
time_thrown: any;
time_thrown: string;
data: any;
path: any;
locations: any;
_showLocations: any;
constructor (name, config: ErrorConfig) {
super((config && config.message) || '');
_showLocations: boolean=false;

constructor (name:string, config: ErrorConfig) {
super((arguments[2] && arguments[2].message) || '');

const t = (arguments[2] && arguments[2].time_thrown) || (new Date()).toISOString();
const m = (arguments[2] && arguments[2].message) || '';
const configData = (arguments[2] && arguments[2].data) || {};
Expand Down Expand Up @@ -51,7 +56,7 @@ class ApolloError extends ExtendableError {

export const isInstance = e => e instanceof ApolloError;

export const createError = (name, config: ErrorConfig) => {
export const createError = (name:string, config: ErrorConfig) => {
assert(isObject(config), 'createError requires a config object as the second parameter');
assert(isString(config.message), 'createError requires a "message" property on the config object passed as the second parameter');
const e = ApolloError.bind(null, name, config);
Expand Down
4 changes: 2 additions & 2 deletions test/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('createError', () => {
},
options: {
showLocations: false,
showPath: false,
showPath: true,
},
});
const iso = new Date().toISOString();
Expand All @@ -27,7 +27,7 @@ describe('createError', () => {
},
options: {
showLocations: true,
showPath: true,
showPath: false,
},
});

Expand Down
2 changes: 0 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"allowJs": true,
Expand Down

0 comments on commit 5665a6a

Please sign in to comment.