Skip to content

Commit

Permalink
fix(graphql): errors should not result in internal error (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
ComfortablyCoding authored Nov 19, 2023
1 parent 68ea256 commit 66b9d27
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
},
"dependencies": {
"@sindresorhus/slugify": "1.1.0",
"lodash": "^4.17.21",
"yup": "^0.32.9",
"@strapi/strapi": "^4.14.0",
"@strapi/utils": "^4.14.0"
"@strapi/utils": "^4.14.0",
"lodash": "^4.17.21",
"yup": "^0.32.9"
},
"devDependencies": {
"eslint": "^8.53.0",
Expand Down
24 changes: 16 additions & 8 deletions server/graphql/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { getPluginService } = require('../utils/getPluginService');
const { isValidFindSlugParams } = require('../utils/isValidFindSlugParams');
const { hasRequiredModelScopes } = require('../utils/hasRequiredModelScopes');
const { sanitizeOutput } = require('../utils/sanitizeOutput');
const { ForbiddenError, ValidationError } = require('@strapi/utils').errors;

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

isValidFindSlugParams({
modelName,
slug,
modelsByName,
publicationState,
});

try {
isValidFindSlugParams({
modelName,
slug,
modelsByName,
publicationState,
});
} catch (error) {
throw new ValidationError(error.message);
}
const { uid, field, contentType } = modelsByName[modelName];

await hasRequiredModelScopes(strapi, uid, auth);
try {
await hasRequiredModelScopes(strapi, uid, auth);
} catch (error) {
throw new ForbiddenError();
}

// build query
let query = {
Expand Down

0 comments on commit 66b9d27

Please sign in to comment.