File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ export default async function handler ( req , res ) {
2+ try {
3+ // Construct the external API URL with query parameters
4+ const queryParams = req . url . includes ( "?" ) ? req . url . split ( "?" ) [ 1 ] : "" ;
5+ const apiUrl = `${ process . env . API_URL } /membership${
6+ queryParams ? `?${ queryParams } ` : ""
7+ } `;
8+
9+ // Call the external API with the required headers
10+ const response = await fetch ( apiUrl , {
11+ method : "GET" ,
12+ headers : {
13+ "Content-Type" : "application/json" ,
14+ key : process . env . ACCESS_KEY ,
15+ } ,
16+ } ) ;
17+
18+ // Handle errors from the external API
19+ if ( ! response . ok ) {
20+ const errorData = await response . text ( ) ; // Capture the error response
21+ console . error ( "API Error Response:" , errorData ) ;
22+ return res
23+ . status ( response . status )
24+ . json ( { message : "Error fetching membership data" , error : errorData } ) ;
25+ }
26+
27+ // Parse and return the response
28+ const data = await response . json ( ) ;
29+ res . status ( 200 ) . json ( data ) ;
30+ } catch ( error ) {
31+ console . error ( "Internal Server Error:" , error ) ; // Log full error details
32+ res
33+ . status ( 500 )
34+ . json ( { message : "Internal Server Error" , error : error . message } ) ;
35+ }
36+ }
You can’t perform that action at this time.
0 commit comments