Skip to content

Commit 7145ffa

Browse files
committedApr 13, 2018
Add documentation for internalData property
1 parent a710b53 commit 7145ffa

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed
 

‎README.md

+28-4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ const resolverThatThrowsError = (root, params, context) => {
5858
throw new FooError({
5959
data: {
6060
something: 'important'
61+
},
62+
internalData: {
63+
error: `The SQL server died.`
6164
}
6265
});
6366
}
@@ -83,18 +86,39 @@ Witness glorious simplicity:
8386
}
8487
```
8588

89+
The `internalData` property is meant for data you want to store on the error object (e.g. for logging), but not send out to your end users.
90+
You can utilize this data for logging purposes.
91+
92+
```js
93+
import { isInstance as isApolloErrorInstance, formatError as formatApolloError } from 'apollo-errors';
94+
95+
function formatError(error) {
96+
const { originialError } = error;
97+
if (isApolloErrorInstance(originalError)) {
98+
// log internalData to stdout but not include it in the formattedError
99+
console.log(JSON.stringify({
100+
type: `error`,
101+
data: originalError.data,
102+
internalData: originalError.internalData
103+
}));
104+
}
105+
return formatApolloError(error)
106+
}
107+
108+
```
109+
86110
## API
87111

88-
### ApolloError ({ [time_thrown: String, data: Object, message: String ]})
112+
### ApolloError ({ [time_thrown: String, data: Object, internalData: object message: String ]})
89113

90114
Creates a new ApolloError object. Note that `ApolloError` in this context refers
91115
to an error class created and returned by `createError` documented below. Error can be
92-
initialized with a custom `time_thrown` ISODate (default is current ISODate), `data` object (which will be merged with data specified through `createError`, if it exists), and `message` (which will override the message specified through `createError`).
116+
initialized with a custom `time_thrown` ISODate (default is current ISODate), `data` object (which will be merged with data specified through `createError`, if it exists), `internalData` object (which will be merged with internalData specified trough `createError`) and `message` (which will override the message specified through `createError`).
93117

94118

95-
### createError(name, {message: String, [data: Object, options: Object]}): ApolloError
119+
### createError(name, {message: String, [data: Object, internalData: object, options: Object]}): ApolloError
96120

97-
Creates and returns an error class with the given `name` and `message`, optionally initialized with the given `data` and `options`. `data` passed to `createError` will later be merged with any data passed to the constructor.
121+
Creates and returns an error class with the given `name` and `message`, optionally initialized with the given `data`, `internalData` and `options`. `data` and `internalData` passed to `createError` will later be merged with any data passed to the constructor.
98122

99123
#### Options (default):
100124

0 commit comments

Comments
 (0)
Please sign in to comment.