in src/SpotifyApi.ts [77:114]
public async makeRequest<TReturnType>(method: "GET" | "POST" | "PUT" | "DELETE", url: string, body: any = undefined, contentType: string | undefined = undefined): Promise<TReturnType> {
try {
const accessToken = await this.authenticationStrategy.getOrCreateAccessToken();
if (isEmptyAccessToken(accessToken)) {
console.warn("No access token found, authenticating now.");
return null as TReturnType;
}
const token = accessToken?.access_token;
const fullUrl = SpotifyApi.rootUrl + url;
const opts: RequestInit = {
method: method,
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": contentType ?? "application/json"
},
body: body ? typeof body === "string" ? body : JSON.stringify(body) : undefined
};
this.sdkConfig.beforeRequest(fullUrl, opts);
const result = await this.sdkConfig.fetch(fullUrl, opts);
this.sdkConfig.afterRequest(fullUrl, opts, result);
if (result.status === 204) {
return null as TReturnType;
}
await this.sdkConfig.responseValidator.validateResponse(result);
return this.sdkConfig.deserializer.deserialize<TReturnType>(result);
} catch (error) {
const handled = await this.sdkConfig.errorHandler.handleErrors(error);
if (!handled) {
throw error;
}
return null as TReturnType;
}
}