mirror of
https://github.com/strapi/strapi.git
synced 2025-12-27 15:13:21 +00:00
Fix custom response body
This commit is contained in:
parent
2e6d5c9a1a
commit
82603ad480
@ -153,9 +153,10 @@ module.exports = {
|
||||
const { env } = ctx.params;
|
||||
let params = ctx.request.body;
|
||||
|
||||
if (!env || _.isEmpty(_.find(Service.getEnvironments(), { name: env }))) return ctx.badRequest(null, [{ messages: [{ id: 'request.error.environment.unknown' }] }]);
|
||||
|
||||
const [name] = _.keys(params.database.connections);
|
||||
|
||||
if (!env || _.isEmpty(_.find(Service.getEnvironments(), { name: env }))) return ctx.badRequest(null, [{ messages: [{ id: 'request.error.environment.unknown' }] }]);
|
||||
if (!name || _.find(Service.getDatabases(env), { name })) return ctx.badRequest(null, [{ messages: [{ id: 'request.error.database.exist' }] }]);
|
||||
|
||||
const model = Service.databases(name, env);
|
||||
|
||||
@ -37,18 +37,23 @@ module.exports = strapi => {
|
||||
// Log error.
|
||||
strapi.log.error(error);
|
||||
|
||||
|
||||
// Wrap error into a Boom's response.
|
||||
ctx.status = error.status || 500;
|
||||
ctx.body = _.get(ctx.body, 'isBoom')
|
||||
? ctx.body || error && error.message
|
||||
: Boom.wrap(error, ctx.status, ctx.body || error.message);
|
||||
}
|
||||
|
||||
|
||||
// Empty body is considered as `notFound` response.
|
||||
if (!ctx.body) {
|
||||
ctx.notFound();
|
||||
}
|
||||
|
||||
if (ctx.body.isBoom && ctx.body.data) {
|
||||
ctx.body.output.payload.message = ctx.body.data;
|
||||
}
|
||||
|
||||
// Format `ctx.body` and `ctx.status`.
|
||||
ctx.status = ctx.body.isBoom ? ctx.body.output.statusCode : ctx.status;
|
||||
ctx.body = ctx.body.isBoom ? ctx.body.output.payload : ctx.body;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user