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 { try {
const firstName = e.currentTarget.firstName.value || '' const firstName = e.currentTarget.firstName.value || ''
const lastName = e.currentTarget.lastName.value || '' const lastName = e.currentTarget.lastName.value || ''
const email = e.currentTarget.email.value
const apiResponse = await api.subscribeToMailingList( const apiResponse = await api.subscribeToMailingList({
e.currentTarget.email.value, email,
e.currentTarget.firstName.value + ' ' + e.currentTarget.lastName.value, firstName,
) lastName,
})
setSuccessMessage(apiResponse.message) setSuccessMessage(apiResponse.message)
} catch (error) { } catch (error) {

View File

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

View File

@ -93,6 +93,13 @@ export class ApiService {
body: JSON.stringify(payload), 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() return res.json()
} }
} }