-
Notifications
You must be signed in to change notification settings - Fork 9
feat: update createArtist to use POST /api/artist endpoint #1459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: update createArtist to use POST /api/artist endpoint #1459
Conversation
Update lib/createArtist.tsx to call the migrated /api/artist/create endpoint on recoup-api instead of the local endpoint. Related to MYC-3924: Migrate /api/artist/create REST endpoint Co-Authored-By: Claude Opus 4.5 <[email protected]>
Updated to call the new REST-compliant POST /api/artist endpoint with JSON body instead of GET /api/artist/create with query params. Co-Authored-By: Claude Opus 4.5 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| const response = await fetch( | ||
| `/api/artist/create?name=${encodeURIComponent(name)}&account_id=${account_id}`, | ||
| ); | ||
| const response = await fetch(`${NEW_API_BASE_URL}/api/artist`, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code doesn't check if the API response was successful before attempting to parse and access data.artist, which deviates from the established error-handling pattern used throughout the codebase. This could cause the function to return undefined instead of null when the API request fails with an HTTP error.
View Details
📝 Patch Details
diff --git a/lib/createArtist.tsx b/lib/createArtist.tsx
index 36e1565d..84f82698 100644
--- a/lib/createArtist.tsx
+++ b/lib/createArtist.tsx
@@ -9,10 +9,15 @@ const createArtist = async (name: string, account_id: string) => {
},
body: JSON.stringify({ name, account_id }),
});
- const data = await response.json();
+ if (!response.ok) {
+ return null;
+ }
+
+ const data = await response.json();
return data.artist;
} catch (error) {
+ console.error(error);
return null;
}
};
Analysis
Missing response.ok check in createArtist() allows undefined return on API errors
What fails: lib/createArtist.tsx doesn't check response.ok before parsing JSON, causing the function to return undefined instead of null when the API returns HTTP error status codes with valid JSON responses.
How to reproduce:
// In lib/createArtist.tsx (before fix):
const createArtist = async (name: string, account_id: string) => {
try {
const response = await fetch(` The API endpoint (app/api/artist/create/route.ts) returns error responses without an artist field:
- Status 400:
{ message: "Missing required parameters: name and account_id" } - Status 500:
{ message: "Failed to create artist" } - Status 400 on catch:
{ message: "..." }
Result: Function inconsistently returns undefined for API errors, while all 49+ similar API calls in the codebase use the response.ok pattern to return null on errors.
Expected: Function should check response.ok before attempting to parse response (following the established pattern in lib/getFanSegments.tsx, lib/getConversations.tsx, lib/getHandles.tsx, and 46+ other files).
Fix applied: Added if (!response.ok) return null; check after fetch, consistent with codebase patterns. Also restored console.error(error) logging in catch block for debugging visibility.
Summary
Test plan
🤖 Generated with Claude Code