improve logging?

This commit is contained in:
Thomas Ruoff
2022-06-23 21:36:43 +02:00
committed by Thomas Ruoff
parent 942066bc7a
commit 00002a62d2
15 changed files with 91 additions and 50 deletions

View File

@@ -1,3 +1,4 @@
export { reportWebVitals } from 'next-axiom'
import { useEffect } from 'react'
import { useSession, signIn, SessionProvider } from 'next-auth/react'

View File

@@ -6,6 +6,7 @@ import { Booking } from '../../../../db/booking'
import { BILL_STATUS, MILAGE_TARIFS } from '../../../../db/enums'
import { getMilageMax } from '../../../../db/index'
import { daysFormatFrontend } from '../../../../helpers/date'
import { log } from '../../../../helpers/log'
import { getBillTotal, createBill, patchBill } from '../../../../helpers/bill'
import { getBookingStatus } from '../../../../helpers/booking'
import { getServerSideBooking } from '../../../../lib/getServerSideProps'
@@ -109,7 +110,7 @@ function BookingBillPage({
setBooking(booking)
} catch (error) {
setStoringError('Buchung konnte nicht gespeichert werden!')
console.error('Failed to store booking', error)
log.error('Failed to store booking', error)
}
setStoringInProgress(false)
}
@@ -197,9 +198,8 @@ function BookingBillPage({
>
-
</button>
<label className="flabel inline">{`Kostenpunkt ${
index + 1
}`}</label>
<label className="flabel inline">{`Kostenpunkt ${index + 1
}`}</label>
</div>
<div className="ml-10 mb-3" key={`input{index}`}>
<Input

View File

@@ -7,6 +7,7 @@ import { getServerSideBooking } from '../../../../lib/getServerSideProps'
import { Booking } from '../../../../db/booking'
import { getBookingStatus, patchBooking } from '../../../../helpers/booking'
import { daysFormatFrontend } from '../../../../helpers/date'
import { log } from '../../../../helpers/log'
import { BOOKING_STATUS } from '../../../../db/enums'
export const getServerSideProps = getServerSideBooking
@@ -30,7 +31,7 @@ function ShowBookingAdmin({ booking: bookingProp }: { booking: Booking }) {
setBooking(updatedBooking)
} catch (error) {
setStoringBookingError('Buchung konnte nicht gespeichert werden.')
console.error('Failed to store booking', error)
log.error('Failed to store booking', error)
}
setStoringBooking(false)
}

View File

@@ -1,6 +1,7 @@
import { NextApiRequest, NextApiResponse } from 'next'
import { Bill } from '../../../../db/bill'
import { createBill, patchBill } from '../../../../db/index'
import { log } from '../../../../helpers/log'
export default async function billHandler(
req: NextApiRequest,
@@ -20,7 +21,7 @@ export default async function billHandler(
bill = await createBill(bookingUUID, req.body)
res.status(200).json(bill)
} catch (e) {
console.error(e)
log.error('Failed to store bill', e)
res.status(500).end(`Internal Server Error...Guru is meditating...`)
return
}
@@ -30,7 +31,7 @@ export default async function billHandler(
bill = await patchBill(bookingUUID, req.body)
res.status(200).json(bill)
} catch (e) {
console.error(e)
log.error('Failed to patch bill', e)
res.status(500).end(`Internal Server Error...Guru is meditating...`)
return
}

View File

@@ -7,6 +7,7 @@ import {
sendBookingRejected,
sendBookingCanceled,
} from '../../../../helpers/mail'
import { log } from '../../../../helpers/log'
function changedStatus(
previous: Booking,
@@ -72,7 +73,7 @@ export default async function userHandler(
res.status(200).json(current)
} catch (error) {
console.error('failed patch booking', error)
log.error('failed patch booking', error)
res.status(400).end(`Failed to save booking: ${error.message}`)
}
break

View File

@@ -2,6 +2,7 @@ import { Error } from 'mongoose'
import { NextApiRequest, NextApiResponse } from 'next'
import { Booking } from '../../../db/booking'
import { createBooking } from '../../../db/index'
import { log } from '../../../helpers/log'
import {
sendReceivedBookingAdminMail,
sendReceivedBookingBookerMail,
@@ -21,20 +22,23 @@ export default async function userHandler(
booking = await createBooking(req.body)
res.status(200).json(booking)
} catch (e) {
console.error(e)
if (e instanceof Error.ValidationError) {
res.status(400).json({ message: e.message, errors: e.errors })
return
}
log.error('Failed to store booking', e)
res.status(500).end(`Internal Server Error...Guru is meditating...`)
return
}
console.log(`received booking ${booking.uuid} from {booking.email}`)
log.info(`received booking ${booking.uuid} from {booking.email}`)
await sendReceivedBookingAdminMail(booking)
console.log(`send booking ${booking.uuid} received to admin`)
log.info(`send booking ${booking.uuid} received to admin`, booking)
await sendReceivedBookingBookerMail(booking)
console.log(`send booking ${booking.uuid} received to {booking.email}`)
log.info(
`send booking ${booking.uuid} received to {booking.email}`,
booking
)
break
default:
res.setHeader('Allow', ['POST'])

View File

@@ -4,6 +4,7 @@ import { getServerSideBooking } from '../../../lib/getServerSideProps'
import { Booking } from '../../../db/booking'
import { BOOKING_STATUS } from '../../../db/enums'
import { daysFormatFrontend } from '../../../helpers/date'
import { log } from '../../../helpers/log'
import { getBookingStatus, cancelBooking } from '../../../helpers/booking'
export const getServerSideProps = getServerSideBooking
@@ -34,7 +35,7 @@ export default function ShowBooking({
setStoringBookingError(
'Buchung konnte nicht storniert werden. Schreiben Sie uns eine E-Mail!'
)
console.error('Failed to store booking', error)
log.error('Failed to store booking', error)
}
setStoringBooking(false)
}
@@ -53,16 +54,16 @@ export default function ShowBooking({
{[BOOKING_STATUS.CONFIRMED, BOOKING_STATUS.REQUESTED].includes(
booking.status
) && (
<div className="my-6">
<button
onClick={onCancelBooking}
className="btn btn-red"
disabled={storingBooking}
>
Buchung Stornieren
</button>
</div>
)}
<div className="my-6">
<button
onClick={onCancelBooking}
className="btn btn-red"
disabled={storingBooking}
>
Buchung Stornieren
</button>
</div>
)}
</Layout>
)
}