Skip to content

Commit fd190d7

Browse files
fix: fix minor issues to see why newsletter does not work (#483)
1 parent f080cb0 commit fd190d7

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

libs/blog-bff/newsletter/src/lib/api.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { NewsletterClient } from './newsletter-client';
1212
type NewsletterBindings = {
1313
BREVO_API_KEY: string;
1414
BREVO_API_URL: string;
15+
IS_PROD?: string;
1516
};
1617

1718
const app = new Hono<{
@@ -84,18 +85,20 @@ app.post('/subscribe', async (c) => {
8485
smsBlacklisted: false,
8586
listIds,
8687
});
88+
} else {
89+
throw err;
8790
}
8891
}
8992

9093
return c.json({ success: true }, 200);
9194
} catch (e) {
9295
if (e instanceof v.ValiError) {
93-
return c.json('Email validation error', 400);
96+
return c.json({ error: 'Email validation error' }, 400);
9497
}
9598
if (e instanceof HTTPException) {
96-
return c.json('Post method fail', 400);
99+
return c.json({ error: 'Post method fail' }, 400);
97100
}
98-
return c.json('Unknown error', 400);
101+
return c.json({ error: 'Unknown error' }, 400);
99102
}
100103
});
101104

libs/blog-bff/newsletter/src/lib/newsletter-client.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ export class NewsletterClient {
4141

4242
if (!res.ok) {
4343
const errorBody = await res.json();
44-
throw new Error(errorBody);
44+
const error = new Error(errorBody.message || 'API request failed');
45+
Object.assign(error, errorBody);
46+
throw error;
4547
}
4648

4749
if (res.status === 204) {

0 commit comments

Comments
 (0)