Skip to content

Commit

Permalink
Use body for 204 if defined
Browse files Browse the repository at this point in the history
  • Loading branch information
Joakim committed Feb 14, 2022
1 parent c44570f commit fec0ed8
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions KoaResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,11 @@ class Resource {
switch (ctx.state.__rMethod) {
case 'index':
ctx.status = 200;
ctx.body = [];
ctx.body = ctx.body || [];
break;
default:
ctx.status = 200;
ctx.body = {};
ctx.body = ctx.body || {};
break;
}
break;
Expand Down Expand Up @@ -800,19 +800,19 @@ class Resource {
if (utils.get(ctx, 'state.session.constructor.name') !== 'ClientSession') ctx.state.session = await this.model.startSession();
if (!ctx.state.session.inTransaction()) await ctx.state.session.startTransaction();
writeOptions.session = ctx.state.session;
const errors = []
const errors = [];
ctx.state.item = await Promise.all(ctx.state.item.map(item => item.save(writeOptions)))
.catch((err) => {
errors.push(err)
errors.push(err);
})
.finally((result) => {
if (errors.length) {
const err = new Error(`Error${errors.length > 1 ? 's' : ''} occured while trying to save document into database`);
err.name = 'DatabaseError';
err.errors = errors
throw err
err.errors = errors;
throw err;
}
else return result
else return result;
});
await ctx.state.session.commitTransaction();
}
Expand Down

0 comments on commit fec0ed8

Please sign in to comment.