return 400 when validation fails

This commit is contained in:
Thomas Ruoff
2020-08-31 21:54:19 +02:00
committed by Thomas Ruoff
parent 96060d1415
commit cf92a69fa7
2 changed files with 8 additions and 4 deletions

View File

@@ -61,7 +61,12 @@ export async function createBooking({
const bookedDays = await getBookedDays()
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()