-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(xo-server/rest-api): ability to delete group #8277
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add in the PR description a small example of the request call.
See #8276 (comment)
api.delete( | ||
'/:collection(groups)/:id', | ||
wrap(async (req, res) => { | ||
const { id } = req.params | ||
await app.deleteGroup(id) | ||
res.sendStatus(204) | ||
}) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
app.deleteGroup
can throw, so this needs to be handled, otherwise the request will return an internal server error, and will not help the end user.
Something like this should work and be enough for now:
try {
await app.deleteGroup(id)
res.status(204) // HTTP status 204 -> success
} catch (error) {
res.json({ error: error.message })
if (noSuchObject.is(error)) {
res.status(404) // HTTP status 404 -> resource not found (so the group with the given id was not found)
} else {
res.status(500) // HTTP status 500 -> internal server error (unhandled error in this case)
}
}
res.send()
Description
Checklist
Fixes #007
,See xoa-support#42
,See https://...
)Introduced by
CHANGELOG.unreleased.md
Review process
Notes: