File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -162,6 +162,12 @@ async function resolveTeam(
162162 ) ;
163163}
164164
165+ /** Check whether an API error is about an invalid platform value */
166+ function isPlatformError ( error : ApiError ) : boolean {
167+ const detail = error . detail ?? error . message ;
168+ return detail . includes ( "platform" ) && detail . includes ( "Invalid" ) ;
169+ }
170+
165171/**
166172 * Create a project with user-friendly error handling.
167173 * Wraps API errors with actionable messages instead of raw HTTP status codes.
@@ -182,6 +188,17 @@ async function createProjectWithErrors(
182188 `View it: sentry project view ${ orgSlug } /${ name } `
183189 ) ;
184190 }
191+ if ( error . status === 400 && isPlatformError ( error ) ) {
192+ const list = PLATFORMS . map ( ( p ) => ` ${ p } ` ) . join ( "\n" ) ;
193+ throw new CliError (
194+ `Invalid platform '${ platform } '.\n\n` +
195+ "Specify it using:\n" +
196+ ` sentry project create ${ orgSlug } /${ name } <platform>\n\n` +
197+ "Or:\n" +
198+ ` - Available platforms:\n\n${ list } \n` +
199+ " - Full list: https://docs.sentry.io/platforms/"
200+ ) ;
201+ }
185202 if ( error . status === 404 ) {
186203 throw new CliError (
187204 `Team '${ teamSlug } ' not found in ${ orgSlug } .\n\n` +
Original file line number Diff line number Diff line change @@ -227,6 +227,28 @@ describe("project create", () => {
227227 expect ( err . message ) . toContain ( "--team <team-slug>" ) ;
228228 } ) ;
229229
230+ test ( "handles 400 invalid platform with platform list" , async ( ) => {
231+ createProjectSpy . mockRejectedValue (
232+ new ApiError (
233+ "API request failed: 400 Bad Request" ,
234+ 400 ,
235+ '{"platform":["Invalid platform"]}'
236+ )
237+ ) ;
238+
239+ const { context } = createMockContext ( ) ;
240+ const func = await createCommand . loader ( ) ;
241+
242+ const err = await func
243+ . call ( context , { json : false } , "my-app" , "node" )
244+ . catch ( ( e : Error ) => e ) ;
245+ expect ( err ) . toBeInstanceOf ( CliError ) ;
246+ expect ( err . message ) . toContain ( "Invalid platform 'node'" ) ;
247+ expect ( err . message ) . toContain ( "Available platforms:" ) ;
248+ expect ( err . message ) . toContain ( "javascript-nextjs" ) ;
249+ expect ( err . message ) . toContain ( "docs.sentry.io/platforms" ) ;
250+ } ) ;
251+
230252 test ( "wraps other API errors with context" , async ( ) => {
231253 createProjectSpy . mockRejectedValue (
232254 new ApiError ( "API request failed: 403 Forbidden" , 403 , "No permission" )
You can’t perform that action at this time.
0 commit comments