fix: use new api version for subscription

This commit is contained in:
jongomez 2023-10-26 14:50:41 +01:00 committed by Jon
parent 17f716c6ce
commit f9d219c40e
3 changed files with 14 additions and 5 deletions

View File

@ -69,11 +69,13 @@ export default function SubscribeDialogue({
try {
const firstName = e.currentTarget.firstName.value || ''
const lastName = e.currentTarget.lastName.value || ''
const email = e.currentTarget.email.value
const apiResponse = await api.subscribeToMailingList(
e.currentTarget.email.value,
e.currentTarget.firstName.value + ' ' + e.currentTarget.lastName.value,
)
const apiResponse = await api.subscribeToMailingList({
email,
firstName,
lastName,
})
setSuccessMessage(apiResponse.message)
} catch (error) {

View File

@ -108,7 +108,7 @@ export default async function handler(
if (subscribed) {
return res.status(200).json({
message: 'already subscribed',
message: 'Already subscribed',
data: {},
})
}

View File

@ -93,6 +93,13 @@ export class ApiService {
body: JSON.stringify(payload),
})
if (res.status >= 400) {
// Handle errors for status codes 400 and 500
const errorMessage = `Error: ${res.status} - ${res.statusText}`
console.error(errorMessage)
throw new Error(errorMessage)
}
return res.json()
}
}