Skip to content

Commit 42269a0

Browse files
author
Andrew E. Rhyne
committed
Release 1.2.1
1 parent 9be5546 commit 42269a0

File tree

6 files changed

+18
-8
lines changed

6 files changed

+18
-8
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
1.2.1 / 2016-12-07
2+
==================
3+
* Fixed a bug with overriding message serialization
14

25
1.2.0 / 2016-12-07
36
==================
@@ -13,5 +16,4 @@
1316

1417
1.0.1 / 2016-11-10
1518
==================
16-
1719
* Initial release (@thebigredgeek)

dist/index.js

+5-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "apollo-errors",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"description": "Machine-readable custom errors for Apollostack's GraphQL server",
55
"main": "dist/index.js",
66
"scripts": {

src/index.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ const errorMap = new Map();
44

55
const DELIMITER = '/::/';
66

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

1013
class ApolloError extends ExtendableError {
@@ -22,6 +25,7 @@ class ApolloError extends ExtendableError {
2225
super(serializeName([
2326
name,
2427
t,
28+
(m !== message ? m : 'null'),
2529
Object.assign({}, d, {
2630
toString: () => JSON.stringify(d)
2731
}),
@@ -60,13 +64,14 @@ export const createError = (name, data = { message: 'An error has occurred', opt
6064
};
6165

6266
export const formatError = (originalError, returnNull = false) => {
63-
const [ name, thrown_at, d ] = deserializeName(originalError.message);
67+
const [ name, thrown_at, m, d ] = deserializeName(originalError.message);
6468
const { locations, path } = originalError;
6569
const data = d !== undefined ? JSON.parse(d) : {};
6670
if (!name) return returnNull ? null : originalError;
6771
const CustomError = errorMap.get(name);
6872
if (!CustomError) return returnNull ? null : originalError;
6973
const error = new CustomError({
74+
message: m === 'null' ? undefined : m,
7075
thrown_at,
7176
data,
7277
locations,

test/spec.js

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ describe('formatError', () => {
5555
});
5656

5757
const e = new FooError({
58+
message: 'A foo 2.0 error has occurred',
5859
data: {
5960
oh: 'shit'
6061
}

0 commit comments

Comments
 (0)