Reputation: 451
I'm trying to create an axios abstraction, but I'm getting this error on catch block.
Object is of type 'unknown'.
import axios, { AxiosResponse } from "axios";
import { injectable } from "inversify";
import { HttpRequest, HttpResponse, IHttp } from "../../interfaces/Ihttp";
@injectable()
export class AxiosHttpClient implements IHttp {
async request(params: HttpRequest): Promise<HttpResponse> {
let axiosResponse: AxiosResponse;
try {
axiosResponse = await axios.request({
url: params.url,
method: params.method,
data: params.body,
headers: params.headers,
});
} catch (error) {
axiosResponse = error.response;
}
return {
statusCode: axiosResponse.status,
data: axiosResponse.data,
};
}
}
Upvotes: 2
Views: 2038
Reputation: 451
I solved the problem putting the useUnknownInCatchVariables
option to false in tsconfig.json
Upvotes: 5