File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -136,6 +136,27 @@ describe('resolveAtlassianCloudId', () => {
136136 expect ( error . message ) . not . toContain ( 'provider-body-secret-marker' )
137137 } )
138138
139+ it ( 'omits malformed successful response bodies from selector discovery errors' , async ( ) => {
140+ fetchMock . mockResolvedValue ( {
141+ ok : true ,
142+ status : 200 ,
143+ headers : new Headers ( ) ,
144+ json : vi
145+ . fn ( )
146+ . mockRejectedValue ( new SyntaxError ( 'invalid provider-body-secret-marker JSON payload' ) ) ,
147+ } )
148+
149+ const error = await resolveAtlassianCloudId (
150+ options ( {
151+ retryOptions : { ...FAST , omitResponseBodyFromErrors : true } ,
152+ } )
153+ ) . catch ( ( caught ) => caught as Error )
154+
155+ expect ( error . message ) . toBe ( 'Failed to fetch Jira accessible resources: invalid JSON response' )
156+ expect ( error . message ) . not . toContain ( 'provider-body-secret-marker' )
157+ expect ( fetchMock ) . toHaveBeenCalledTimes ( 1 )
158+ } )
159+
139160 it ( 'does not pin a failure in the cache' , async ( ) => {
140161 fetchMock . mockResolvedValueOnce ( failure ( 403 , { message : 'nope' } ) )
141162 await expect ( resolveAtlassianCloudId ( options ( { retryOptions : FAST } ) ) ) . rejects . toThrow ( )
Original file line number Diff line number Diff line change @@ -172,7 +172,14 @@ export function fetchAtlassianDiscoveryJson<T>(
172172 throw error
173173 }
174174
175- return ( await response . json ( ) ) as T
175+ try {
176+ return ( await response . json ( ) ) as T
177+ } catch ( error ) {
178+ if ( omitResponseBodyFromErrors ) {
179+ throw new Error ( `${ failureLabel } : invalid JSON response` )
180+ }
181+ throw error
182+ }
176183 } ,
177184 { ...ATLASSIAN_DISCOVERY_RETRY_OPTIONS , ...effectiveRetryOptions }
178185 )
You can’t perform that action at this time.
0 commit comments