Custom zoom response handler (#5017)

pull/4982/head
alannnc 2022-10-14 18:24:57 -06:00 committed by GitHub
parent 1455a6f603
commit e54bdb4c46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 4 deletions

View File

@ -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);
@ -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;
};
@ -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;