Estructura para el token de alai
cabecera automatica de bearer para todas las requests a alai
This commit is contained in:
@@ -19,7 +19,7 @@ export class HttpClient {
|
||||
|
||||
constructor(args: {
|
||||
baseURL: string,
|
||||
headers: Object,
|
||||
headers: Record<string, string>,
|
||||
jwtManager: JWTProvider<{}> // todo: asociar el tipo de token,
|
||||
jwtService?: IJWTService<any>
|
||||
}) {
|
||||
@@ -37,7 +37,7 @@ export class HttpClient {
|
||||
// token valido de forma preventiva
|
||||
const token = await this.jwtManager.getAccessToken()
|
||||
|
||||
if (token == undefined) throw new Error("No se ha obtenido el token para la peticion")
|
||||
if (token == undefined) throw new Error("No se ha obtenido el token para la petición")
|
||||
|
||||
config.headers.Authorization = `Bearer ${this.jwtManager.authToken!.rawToken}`
|
||||
console.log("request completa", config.data)
|
||||
@@ -50,8 +50,7 @@ export class HttpClient {
|
||||
this.client.interceptors.response.use(
|
||||
(response) => {
|
||||
return response;
|
||||
},
|
||||
async (error) => {
|
||||
}, async (error) => {
|
||||
// TODO: Esta parte no tiene tipos, hay que asegurar el error
|
||||
const req = error.config
|
||||
console.error("[http] Error en la respuesta ", error, error.response)
|
||||
@@ -61,8 +60,17 @@ export class HttpClient {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
get get() {
|
||||
return this.client.get
|
||||
}
|
||||
|
||||
get post() {
|
||||
return this.client.post
|
||||
}
|
||||
|
||||
get patch() {
|
||||
return this.client.patch
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user