Skip to content

Commit

Permalink
Custom zoom response handler (#5017) (#5019)
Browse files Browse the repository at this point in the history
  • Loading branch information
alannnc authored Oct 15, 2022
1 parent 356287c commit f310039
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions packages/app-store/zoomvideo/lib/VideoApiAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ const zoomAuth = (credential: Credential) => {
grant_type: "refresh_token",
}),
});
const responseBody = await handleErrorsJson(response);

const responseBody = await handleZoomResponse(response);

// We check the if the new credentials matches the expected response structure
const parsedToken = zoomRefreshedTokenSchema.safeParse(responseBody);
Expand Down Expand Up @@ -223,15 +224,15 @@ const ZoomVideoApiAdapter = (credential: Credential): VideoApiAdapter => {
const fetchZoomApi = async (endpoint: string, options?: RequestInit) => {
const auth = zoomAuth(credential);
const accessToken = await auth.getToken();
const responseBody = await fetch(`https://api.zoom.us/v2/${endpoint}`, {
const response = await fetch(`https://api.zoom.us/v2/${endpoint}`, {
method: "GET",
...options,
headers: {
Authorization: "Bearer " + accessToken,
...options?.headers,
},
}).then(handleErrorsJson);

});
const responseBody = await handleErrorsJson(response);
return responseBody;
};

Expand Down Expand Up @@ -304,4 +305,17 @@ const ZoomVideoApiAdapter = (credential: Credential): VideoApiAdapter => {
};
};

const handleZoomResponse = async (response: Response) => {
if (response.headers.get("content-encoding") === "gzip") {
const responseString = await response.text();
return JSON.parse(responseString);
}
if (!response.ok && response.status < 200 && response.status >= 300) {
response.json().then(console.log);
throw Error(response.statusText);
}

return response.json();
};

export default ZoomVideoApiAdapter;

1 comment on commit f310039

@vercel
Copy link

@vercel vercel bot commented on f310039 Oct 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

cal – ./

cal-git-production-cal.vercel.app
cal-cal.vercel.app
app.cal.com
app.calendso.com

Please sign in to comment.