Skip to content

Commit

Permalink
bug\9385-Binny-AnalyticsForMismatchedContentType (#9391)
Browse files Browse the repository at this point in the history
Co-authored-by: Theo Bentum <[email protected]>
  • Loading branch information
dumathane and theodur authored Aug 16, 2024
1 parent abacf52 commit 30010d6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
9 changes: 9 additions & 0 deletions VAMobile/src/constants/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ import { Event, EventParams, UserAnalytic } from 'utils/analytics'
*/
/*eslint id-length: ["error", { "max": 24 }]*/
export const Events = {
vama_9385_api_cType: (endpoint: string, contentType: string): Event => {
return {
name: 'vama_9385_api_cType',
params: {
endpoint: endpoint,
contentType: contentType,
},
}
},
vama_accordion_click: (section: string, isOpened: boolean): Event => {
return {
name: 'vama_accordion_click',
Expand Down
2 changes: 1 addition & 1 deletion VAMobile/src/store/api/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ context('api', () => {
const responseBlob = new Blob(['Success'])
const response = new Response(responseBlob, { status: 200, headers: { 'Content-Type': 'text/html' } })
fetch.mockResolvedValue(response)
const result = await get<Types.UserData>('/foo')
const result = await post('/v0/user/logged-in')
expect(result).toEqual(undefined)
})
})
6 changes: 5 additions & 1 deletion VAMobile/src/store/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,11 @@ const call = async function <T>(

// Guard against responses that can't be parsed as JSON
if (!response.headers.get('Content-Type')?.startsWith('application/json')) {
return
if (endpoint === '/v0/user/logged-in') {
return
} else {
logAnalyticsEvent(Events.vama_9385_api_cType(endpoint, response.headers.get('Content-Type') || ''))
}
}

// No errors found, return the response
Expand Down

0 comments on commit 30010d6

Please sign in to comment.