Include more details when throwing errors for debugging in Sentry * WIP throw errors with more details for debugging in Sentry * Fix throwing response-data * Clearer message when a response fails * Add message to errors * better typings * . * Try to send profileID and membershipNumber to Sentry when we fail to parse the apiResponse * rename notFound -> notFoundError * Merge branch 'master' of bitbucket.org:scandic-swap/web into chore/add-error-details-for-sentry Approved-by: Linus Flood
65 lines
1.6 KiB
TypeScript
65 lines
1.6 KiB
TypeScript
import "server-only"
|
|
|
|
import z from "zod"
|
|
|
|
import { createCounter } from "@scandic-hotels/common/telemetry"
|
|
|
|
import * as api from "../../../api"
|
|
import { extractResponseDetails, serverErrorByStatus } from "../../../errors"
|
|
import { safeProtectedServiceProcedure } from "../../../procedures"
|
|
import { toApiLang } from "../../../utils"
|
|
|
|
const validatePartnerPaymentInput = z.object({
|
|
confirmationNumber: z.string(),
|
|
})
|
|
|
|
export const validatePartnerPayment = safeProtectedServiceProcedure
|
|
.input(validatePartnerPaymentInput)
|
|
.use(async ({ ctx, next }) => {
|
|
const token = await ctx.getScandicUserToken()
|
|
|
|
return next({
|
|
ctx: {
|
|
token,
|
|
},
|
|
})
|
|
})
|
|
.mutation(async function ({ ctx, input }) {
|
|
const { confirmationNumber } = input
|
|
const getValidateBooking = createCounter("booking.validate")
|
|
const metricsValidateBooking = getValidateBooking.init({
|
|
confirmationNumber,
|
|
})
|
|
|
|
metricsValidateBooking.start()
|
|
|
|
const apiResponse = await api.put(
|
|
api.endpoints.v1.Booking.validatePartnerPayment(confirmationNumber),
|
|
{
|
|
headers: {
|
|
Authorization: `Bearer ${ctx.token ?? ctx.serviceToken}`,
|
|
},
|
|
},
|
|
{ language: toApiLang(ctx.lang) }
|
|
)
|
|
|
|
if (!apiResponse.ok) {
|
|
await metricsValidateBooking.httpError(apiResponse)
|
|
|
|
// If the booking is not found, return null.
|
|
if (apiResponse.status === 404) {
|
|
return null
|
|
}
|
|
|
|
throw serverErrorByStatus(
|
|
apiResponse.status,
|
|
await extractResponseDetails(apiResponse),
|
|
"validatePartnerPayment failed"
|
|
)
|
|
}
|
|
|
|
metricsValidateBooking.success()
|
|
|
|
return null
|
|
})
|