Skip to content

Instantly share code, notes, and snippets.

@khaosdoctor
Created February 22, 2019 17:37
Show Gist options
  • Save khaosdoctor/f8b22061003ea15d0b1ae1c3b9734da0 to your computer and use it in GitHub Desktop.
Save khaosdoctor/f8b22061003ea15d0b1ae1c3b9734da0 to your computer and use it in GitHub Desktop.
export function factory (service: ShipService, portService: PortService) {
return [
/**
* Route handler
* =============
*/
rescue(async (req, res) => {
const ship = await service.delete(req.params.shipId, req.onBehalfOf)
await portService.undockShip(ship, 'Ship was deleted', req.onBehalfOf)
res.status(204).end()
}),
(err, _req, _res, next) => {
if (err instanceof ShipNotFoundError) return next(new HttpError.NotFound({ message: err.message, code: 'ship_not_found' }))
next(err)
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment