File tree Expand file tree Collapse file tree 2 files changed +9
-4
lines changed
libs/blog-bff/newsletter/src/lib Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import { NewsletterClient } from './newsletter-client';
1212type NewsletterBindings = {
1313 BREVO_API_KEY : string ;
1414 BREVO_API_URL : string ;
15+ IS_PROD ?: string ;
1516} ;
1617
1718const 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
Original file line number Diff line number Diff 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 ) {
You can’t perform that action at this time.
0 commit comments