Skip to content

Commit

Permalink
Release 1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew E. Rhyne committed Dec 7, 2016
1 parent 9be5546 commit 42269a0
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
1.2.1 / 2016-12-07
==================
* Fixed a bug with overriding message serialization

1.2.0 / 2016-12-07
==================
Expand All @@ -13,5 +16,4 @@

1.0.1 / 2016-11-10
==================

* Initial release (@thebigredgeek)
8 changes: 5 additions & 3 deletions 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.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-errors",
"version": "1.2.0",
"version": "1.2.1",
"description": "Machine-readable custom errors for Apollostack's GraphQL server",
"main": "dist/index.js",
"scripts": {
Expand Down
9 changes: 7 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ const errorMap = new Map();

const DELIMITER = '/::/';

const serializeName = (arr = []) => arr.reduce((str, val) => `${str.length > 0 ? str + DELIMITER : str}${val.toString ? val.toString() : val}`, '');
const serializeName = (arr = []) => arr
.reduce((str, val) => (
`${str.length > 0 ? str + DELIMITER : str}${val.toString ? val.toString() : val}`
), '');
const deserializeName = (name = '') => name.split(DELIMITER);

class ApolloError extends ExtendableError {
Expand All @@ -22,6 +25,7 @@ class ApolloError extends ExtendableError {
super(serializeName([
name,
t,
(m !== message ? m : 'null'),
Object.assign({}, d, {
toString: () => JSON.stringify(d)
}),
Expand Down Expand Up @@ -60,13 +64,14 @@ export const createError = (name, data = { message: 'An error has occurred', opt
};

export const formatError = (originalError, returnNull = false) => {
const [ name, thrown_at, d ] = deserializeName(originalError.message);
const [ name, thrown_at, m, d ] = deserializeName(originalError.message);
const { locations, path } = originalError;
const data = d !== undefined ? JSON.parse(d) : {};
if (!name) return returnNull ? null : originalError;
const CustomError = errorMap.get(name);
if (!CustomError) return returnNull ? null : originalError;
const error = new CustomError({
message: m === 'null' ? undefined : m,
thrown_at,
data,
locations,
Expand Down
1 change: 1 addition & 0 deletions test/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ describe('formatError', () => {
});

const e = new FooError({
message: 'A foo 2.0 error has occurred',
data: {
oh: 'shit'
}
Expand Down

0 comments on commit 42269a0

Please sign in to comment.