mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-04 15:07:13 +01:00
return 400 when validation fails
This commit is contained in:
committed by
Thomas Ruoff
parent
96060d1415
commit
cf92a69fa7
@@ -61,7 +61,12 @@ export async function createBooking({
|
|||||||
const bookedDays = await getBookedDays()
|
const bookedDays = await getBookedDays()
|
||||||
|
|
||||||
if (booking.days.some((day: string) => bookedDays.includes(day))) {
|
if (booking.days.some((day: string) => bookedDays.includes(day))) {
|
||||||
throw new mongoose.Error.ValidationError(booking)
|
const error = new mongoose.Error.ValidationError(booking)
|
||||||
|
error.addError(
|
||||||
|
'endDate',
|
||||||
|
'At least on one day the van is not avaliable. Choose another startDate or endDate.'
|
||||||
|
)
|
||||||
|
throw error
|
||||||
}
|
}
|
||||||
|
|
||||||
let booker = await Booker.findOne({ email }).exec()
|
let booker = await Booker.findOne({ email }).exec()
|
||||||
|
|||||||
@@ -19,9 +19,8 @@ export default async function userHandler(
|
|||||||
res.status(200).json(booking)
|
res.status(200).json(booking)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
|
if (e instanceof Error.ValidationError) {
|
||||||
if (e instanceof Error.ValidatorError) {
|
res.status(400).json({ message: e.message, errors: e.errors })
|
||||||
res.status(400).end(e.message)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
res.status(500).end(`Internal Server Error...Guru is meditating...`)
|
res.status(500).end(`Internal Server Error...Guru is meditating...`)
|
||||||
|
|||||||
Reference in New Issue
Block a user