Skip to content

Commit d87d3b3

Browse files
committed
Use the TypeError class instead of Error for relevant errors.
1 parent ad210f2 commit d87d3b3

File tree

7 files changed

+16
-15
lines changed

7 files changed

+16
-15
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Patch
66

77
- Replaced Node.js deprecated `notEqual` assertions with `notStrictEqual` in tests.
8+
- Use the `TypeError` class instead of `Error` for relevant errors.
89

910
## 11.1.0
1011

src/server/ssr.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ module.exports = async function ssr(
8080
render = ReactDOMServer.renderToStaticMarkup
8181
) {
8282
if (!(graphql instanceof GraphQL))
83-
throw new Error('ssr() argument 1 must be a GraphQL instance.');
83+
throw new TypeError('ssr() argument 1 must be a GraphQL instance.');
8484

8585
// Check argument 2 exists, allowing an undefined value as that is a valid
8686
// React node.
8787
if (arguments.length < 2)
88-
throw new Error('ssr() argument 2 must be a React node.');
88+
throw new TypeError('ssr() argument 2 must be a React node.');
8989

9090
if (typeof render !== 'function')
91-
throw new Error('ssr() argument 3 must be a function.');
91+
throw new TypeError('ssr() argument 3 must be a function.');
9292

9393
// Signal that queries should load at render.
9494
graphql.ssr = true;

src/test/server/ssr.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const listen = require('../listen');
1313

1414
module.exports = (tests) => {
1515
tests.add('`ssr` argument 1 validation', async () => {
16-
const error = new Error('ssr() argument 1 must be a GraphQL instance.');
16+
const error = new TypeError('ssr() argument 1 must be a GraphQL instance.');
1717

1818
await rejects(ssr(), error);
1919
await rejects(ssr(true), error);
@@ -24,7 +24,7 @@ module.exports = (tests) => {
2424

2525
await rejects(
2626
ssr(graphql),
27-
new Error('ssr() argument 2 must be a React node.')
27+
new TypeError('ssr() argument 2 must be a React node.')
2828
);
2929

3030
strictEqual(await ssr(graphql, undefined), '');
@@ -38,7 +38,7 @@ module.exports = (tests) => {
3838

3939
await rejects(
4040
ssr(graphql, node, false),
41-
new Error('ssr() argument 3 must be a function.')
41+
new TypeError('ssr() argument 3 must be a function.')
4242
);
4343
});
4444

src/test/universal/GraphQL.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ module.exports = (tests) => {
271271
reloadOnLoad: true,
272272
resetOnLoad: true,
273273
});
274-
}, new Error('operate() options “reloadOnLoad” and “resetOnLoad” can’t both be true.'));
274+
}, new TypeError('operate() options “reloadOnLoad” and “resetOnLoad” can’t both be true.'));
275275
}
276276
);
277277

src/test/universal/useGraphQL.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,7 +1613,7 @@ module.exports = (tests) => {
16131613
/>
16141614
</GraphQLProvider>
16151615
);
1616-
}, new Error('useGraphQL() options “reloadOnLoad” and “resetOnLoad” can’t both be true.'));
1616+
}, new TypeError('useGraphQL() options “reloadOnLoad” and “resetOnLoad” can’t both be true.'));
16171617
}
16181618
);
16191619

@@ -1622,7 +1622,7 @@ module.exports = (tests) => {
16221622
ReactDOMServer.renderToString(
16231623
<RenderUseGraphQL operation={{ query: '' }} />
16241624
);
1625-
}, new Error('GraphQL context missing.'));
1625+
}, new TypeError('GraphQL context missing.'));
16261626
});
16271627

16281628
tests.add('`useGraphQL` with GraphQL context not a GraphQL instance', () => {
@@ -1632,7 +1632,7 @@ module.exports = (tests) => {
16321632
<RenderUseGraphQL operation={{ query: '' }} />
16331633
</GraphQLContext.Provider>
16341634
);
1635-
}, new Error('GraphQL context must be a GraphQL instance.'));
1635+
}, new TypeError('GraphQL context must be a GraphQL instance.'));
16361636
});
16371637

16381638
tests.add(

src/universal/GraphQL.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ module.exports = class GraphQL {
164164
? fetch
165165
: () =>
166166
Promise.reject(
167-
new Error('Global fetch API or polyfill unavailable.')
167+
new TypeError('Global fetch API or polyfill unavailable.')
168168
);
169169
const cacheValue = {};
170170
const cacheValuePromise = fetcher(url, options)
@@ -245,7 +245,7 @@ module.exports = class GraphQL {
245245
resetOnLoad,
246246
}) => {
247247
if (reloadOnLoad && resetOnLoad)
248-
throw new Error(
248+
throw new TypeError(
249249
'operate() options “reloadOnLoad” and “resetOnLoad” can’t both be true.'
250250
);
251251

src/universal/useGraphQL.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,17 @@ module.exports = function useGraphQL({
5959
resetOnLoad,
6060
}) {
6161
if (reloadOnLoad && resetOnLoad)
62-
throw new Error(
62+
throw new TypeError(
6363
'useGraphQL() options “reloadOnLoad” and “resetOnLoad” can’t both be true.'
6464
);
6565

6666
const graphql = React.useContext(GraphQLContext);
6767

6868
if (typeof graphql === 'undefined')
69-
throw new Error('GraphQL context missing.');
69+
throw new TypeError('GraphQL context missing.');
7070

7171
if (!(graphql instanceof GraphQL))
72-
throw new Error('GraphQL context must be a GraphQL instance.');
72+
throw new TypeError('GraphQL context must be a GraphQL instance.');
7373

7474
const fetchOptionsHash = React.useMemo(() => {
7575
const fetchOptions = graphqlFetchOptions(operation);

0 commit comments

Comments
 (0)