I am having an issue where axios returns an error
cause: Error: unexpected end of file
at BrotliDecoder.zlibOnError [as one rror] (node:zlib:189:17) {
errno: -5,
code: 'Z_BUF_ERROR'
I used this function and i don't understand why, though i've tried the same like a month ago
export async function getCredentials(req: Request, res: Response) {
const { code } = req.query;
const params = new URLSearchParams({
client_id: process.env.CLIENT_ID as string,
client_secret: process.env.CLIENT_SECRET as string,
grant_type: "authorization_code",
code: code as string,
redirect_uri: "http://localhost:3000/api/callback",
});
const response = await axios.post(
"https://discord.com/api/oauth2/token",
params,
{
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
}
);
res.json(await response.data);
}
Thank you!
CodePudding user response:
Sorry for the inconvenience, The solution was accept-encoding
const response = await axios.post(
"https://discord.com/api/oauth2/token",
params,
{
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Accept-Encoding": "*",
},
}
);