Skip to content
This repository was archived by the owner on Sep 16, 2025. It is now read-only.

Commit 66b9d27

Browse files
fix(graphql): errors should not result in internal error (#120)
1 parent 68ea256 commit 66b9d27

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
},
2828
"dependencies": {
2929
"@sindresorhus/slugify": "1.1.0",
30-
"lodash": "^4.17.21",
31-
"yup": "^0.32.9",
3230
"@strapi/strapi": "^4.14.0",
33-
"@strapi/utils": "^4.14.0"
31+
"@strapi/utils": "^4.14.0",
32+
"lodash": "^4.17.21",
33+
"yup": "^0.32.9"
3434
},
3535
"devDependencies": {
3636
"eslint": "^8.53.0",

server/graphql/types.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const { getPluginService } = require('../utils/getPluginService');
33
const { isValidFindSlugParams } = require('../utils/isValidFindSlugParams');
44
const { hasRequiredModelScopes } = require('../utils/hasRequiredModelScopes');
55
const { sanitizeOutput } = require('../utils/sanitizeOutput');
6+
const { ForbiddenError, ValidationError } = require('@strapi/utils').errors;
67

78
const getCustomTypes = (strapi, nexus) => {
89
const { naming } = getPluginService('utils', 'graphql');
@@ -54,16 +55,23 @@ const getCustomTypes = (strapi, nexus) => {
5455
const { modelName, slug, publicationState } = args;
5556
const { auth } = ctx.state;
5657

57-
isValidFindSlugParams({
58-
modelName,
59-
slug,
60-
modelsByName,
61-
publicationState,
62-
});
63-
58+
try {
59+
isValidFindSlugParams({
60+
modelName,
61+
slug,
62+
modelsByName,
63+
publicationState,
64+
});
65+
} catch (error) {
66+
throw new ValidationError(error.message);
67+
}
6468
const { uid, field, contentType } = modelsByName[modelName];
6569

66-
await hasRequiredModelScopes(strapi, uid, auth);
70+
try {
71+
await hasRequiredModelScopes(strapi, uid, auth);
72+
} catch (error) {
73+
throw new ForbiddenError();
74+
}
6775

6876
// build query
6977
let query = {

0 commit comments

Comments
 (0)