Jean-Sébastien Herbaux 5a7a5dc987
[V4] GraphQL - Migrate Users & Permissions GraphQL config to V4 (#10979)
* Migrate UsersPermissions's GQL configuration to V4

* Remove old graphql configuration
2021-09-15 15:44:42 +02:00

28 lines
644 B
JavaScript

'use strict';
const { getOr } = require('lodash/fp');
/**
* Throws an ApolloError if context body contains a bad request
* @param contextBody - body of the context object given to the resolver
* @throws ApolloError if the body is a bad request
*/
function checkBadRequest(contextBody) {
const statusCode = getOr(200, 'statusCode', contextBody);
if (statusCode !== 200) {
const errorMessage = getOr('Bad Request', 'error', contextBody);
const exception = new Error(errorMessage);
exception.code = statusCode || 400;
exception.data = contextBody;
throw exception;
}
}
module.exports = {
checkBadRequest,
};