fix: Optimize the logic for session ID validation and improve error messages.
This commit is contained in:
		
							parent
							
								
									1cb4e921db
								
							
						
					
					
						commit
						721bfecb77
					
				@ -15,7 +15,7 @@ export async function GET(req: NextRequest) {
 | 
				
			|||||||
    } catch (error) {
 | 
					    } catch (error) {
 | 
				
			||||||
      console.error('Error fetching limit:', error);
 | 
					      console.error('Error fetching limit:', error);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      return new NextResponse(JSON.stringify({ error: 'Internal server error' }), {
 | 
					      return new NextResponse(JSON.stringify({ error: 'Internal server error. ' + error }), {
 | 
				
			||||||
        status: 500,
 | 
					        status: 500,
 | 
				
			||||||
        headers: { 'Content-Type': 'application/json' }
 | 
					        headers: { 'Content-Type': 'application/json' }
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
 | 
				
			|||||||
@ -66,12 +66,11 @@ class SunoApi {
 | 
				
			|||||||
    const getSessionUrl = `${SunoApi.CLERK_BASE_URL}/v1/client?_clerk_js_version=4.70.5`;
 | 
					    const getSessionUrl = `${SunoApi.CLERK_BASE_URL}/v1/client?_clerk_js_version=4.70.5`;
 | 
				
			||||||
    // Get session ID
 | 
					    // Get session ID
 | 
				
			||||||
    const sessionResponse = await this.client.get(getSessionUrl);
 | 
					    const sessionResponse = await this.client.get(getSessionUrl);
 | 
				
			||||||
    const sid = sessionResponse.data.response['last_active_session_id'];
 | 
					    if (!sessionResponse?.data?.response?.['last_active_session_id']) {
 | 
				
			||||||
    if (!sid) {
 | 
					      throw new Error("Failed to get session id, you may need to update the SUNO_COOKIE");
 | 
				
			||||||
      throw new Error("Failed to get session id");
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    // Save session ID for later use
 | 
					    // Save session ID for later use
 | 
				
			||||||
    this.sid = sid;
 | 
					    this.sid = sessionResponse.data.response['last_active_session_id'];
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
@ -234,6 +233,7 @@ class SunoApi {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Processes the lyrics (prompt) from the audio metadata into a more readable format.
 | 
					   * Processes the lyrics (prompt) from the audio metadata into a more readable format.
 | 
				
			||||||
   * @param prompt The original lyrics text.
 | 
					   * @param prompt The original lyrics text.
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user