Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions libs/blog-bff/newsletter/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { NewsletterClient } from './newsletter-client';
type NewsletterBindings = {
BREVO_API_KEY: string;
BREVO_API_URL: string;
IS_PROD?: string;
};

const app = new Hono<{
Expand Down Expand Up @@ -84,18 +85,20 @@ app.post('/subscribe', async (c) => {
smsBlacklisted: false,
listIds,
});
} else {
throw err;
}
}

return c.json({ success: true }, 200);
} catch (e) {
if (e instanceof v.ValiError) {
return c.json('Email validation error', 400);
return c.json({ error: 'Email validation error' }, 400);
}
if (e instanceof HTTPException) {
return c.json('Post method fail', 400);
return c.json({ error: 'Post method fail' }, 400);
}
return c.json('Unknown error', 400);
return c.json({ error: 'Unknown error' }, 400);
}
});

Expand Down
4 changes: 3 additions & 1 deletion libs/blog-bff/newsletter/src/lib/newsletter-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export class NewsletterClient {

if (!res.ok) {
const errorBody = await res.json();
throw new Error(errorBody);
const error = new Error(errorBody.message || 'API request failed');
Object.assign(error, errorBody);
throw error;
}

if (res.status === 204) {
Expand Down