Handle Axios timeout globally
MODIFY
src/client/ocpi/CpoOCPIClient.ts
src/client/ocpi/CpoOCPIClient.ts
@@ -83,7 +83,6 @@ export default class CpoOCPIClient extends OCPIClient {
headers: {
Authorization: `Token ${this.ocpiEndpoint.token}`
},
- timeout: Constants.AXIOS_TIMEOUT
});
} catch (error) {
// Handle errors
@@ -174,7 +173,6 @@ export default class CpoOCPIClient extends OCPIClient {
Authorization: `Token ${this.ocpiEndpoint.token}`,
'Content-Type': 'application/json'
},
- timeout: Constants.AXIOS_TIMEOUT
});
} catch (error) {
// Handle errors
@@ -260,7 +258,6 @@ export default class CpoOCPIClient extends OCPIClient {
'Authorization': `Token ${this.ocpiEndpoint.token}`,
'Content-Type': 'application/json'
},
- timeout: Constants.AXIOS_TIMEOUT
}
);
} catch (error) {
@@ -322,7 +319,6 @@ export default class CpoOCPIClient extends OCPIClient {
'Authorization': `Token ${this.ocpiEndpoint.token}`,
'Content-Type': 'application/json'
},
- timeout: Constants.AXIOS_TIMEOUT
});
} catch (error) {
// Handle errors
@@ -379,7 +375,6 @@ export default class CpoOCPIClient extends OCPIClient {
'Authorization': `Token ${this.ocpiEndpoint.token}`,
'Content-Type': 'application/json'
},
- timeout: Constants.AXIOS_TIMEOUT
});
} catch (error) {
// Handle errors
@@ -446,7 +441,6 @@ export default class CpoOCPIClient extends OCPIClient {
Authorization: `Token ${this.ocpiEndpoint.token}`,
'Content-Type': 'application/json'
},
- timeout: Constants.AXIOS_TIMEOUT
});
} catch (error) {
// Handle errors
@@ -563,7 +557,6 @@ export default class CpoOCPIClient extends OCPIClient {
Authorization: `Token ${this.ocpiEndpoint.token}`,
'Content-Type': 'application/json'
},
- timeout: Constants.AXIOS_TIMEOUT
});
} catch (error) {
// Handle errors
@@ -596,7 +589,6 @@ export default class CpoOCPIClient extends OCPIClient {
headers: {
Authorization: `Token ${this.ocpiEndpoint.token}`
},
- timeout: Constants.AXIOS_TIMEOUT
});
} catch (error) {
// Handle errors
@@ -617,7 +609,6 @@ export default class CpoOCPIClient extends OCPIClient {
Authorization: `Token ${this.ocpiEndpoint.token}`,
'Content-Type': 'application/json'
},
- timeout: Constants.AXIOS_TIMEOUT
});
return false;
}
@@ -659,7 +650,6 @@ export default class CpoOCPIClient extends OCPIClient {
headers: {
Authorization: `Token ${this.ocpiEndpoint.token}`
},
- timeout: Constants.AXIOS_TIMEOUT
});
} catch (error) {
// Handle errors
@@ -783,7 +773,6 @@ export default class CpoOCPIClient extends OCPIClient {
headers: {
Authorization: `Token ${this.ocpiEndpoint.token}`
},
- timeout: Constants.AXIOS_TIMEOUT
});
} catch (error) {
// Handle errors

MODIFY
src/client/ocpi/EmspOCPIClient.ts
src/client/ocpi/EmspOCPIClient.ts
@@ -176,7 +176,6 @@ export default class EmspOCPIClient extends OCPIClient {
headers: {
Authorization: `Token ${this.ocpiEndpoint.token}`
},
- timeout: Constants.AXIOS_TIMEOUT
});
} catch (error) {
// Handle errors
@@ -235,7 +234,6 @@ export default class EmspOCPIClient extends OCPIClient {
headers: {
Authorization: `Token ${this.ocpiEndpoint.token}`
},
- timeout: Constants.AXIOS_TIMEOUT
});
} catch (error) {
// Handle errors
@@ -295,7 +293,6 @@ export default class EmspOCPIClient extends OCPIClient {
headers: {
Authorization: `Token ${this.ocpiEndpoint.token}`
},
- timeout: Constants.AXIOS_TIMEOUT
});
} catch (error) {
// Handle errors
@@ -450,7 +447,6 @@ export default class EmspOCPIClient extends OCPIClient {
headers: {
Authorization: `Token ${this.ocpiEndpoint.token}`
},
- timeout: Constants.AXIOS_TIMEOUT
});
} catch (error) {
// Handle errors
@@ -503,7 +499,6 @@ export default class EmspOCPIClient extends OCPIClient {
Authorization: `Token ${this.ocpiEndpoint.token}`,
'Content-Type': 'application/json'
},
- timeout: Constants.AXIOS_TIMEOUT
});
} catch (error) {
// Handle errors
@@ -569,7 +564,6 @@ export default class EmspOCPIClient extends OCPIClient {
'Authorization': `Token ${this.ocpiEndpoint.token}`,
'Content-Type': 'application/json'
},
- timeout: Constants.AXIOS_TIMEOUT
});
} catch (error) {
// Handle errors
@@ -619,7 +613,6 @@ export default class EmspOCPIClient extends OCPIClient {
'Authorization': `Token ${this.ocpiEndpoint.token}`,
'Content-Type': 'application/json'
},
- timeout: Constants.AXIOS_TIMEOUT
});
} catch (error) {
// Handle errors

MODIFY
src/client/ocpi/OCPIClient.ts
src/client/ocpi/OCPIClient.ts
@@ -176,7 +176,6 @@ export default abstract class OCPIClient {
headers: {
'Authorization': `Token ${this.ocpiEndpoint.token}`
},
- timeout: Constants.AXIOS_TIMEOUT
});
} catch (error) {
// Handle errors
@@ -202,7 +201,6 @@ export default abstract class OCPIClient {
headers: {
'Authorization': `Token ${this.ocpiEndpoint.token}`
},
- timeout: Constants.AXIOS_TIMEOUT
});
} catch (error) {
// Handle errors
@@ -230,7 +228,6 @@ export default abstract class OCPIClient {
Authorization: `Token ${this.ocpiEndpoint.token}`,
'Content-Type': 'application/json'
},
- timeout: Constants.AXIOS_TIMEOUT
});
} catch (error) {
// Handle errors
@@ -263,7 +260,6 @@ export default abstract class OCPIClient {
Authorization: `Token ${this.ocpiEndpoint.token}`,
'Content-Type': 'application/json'
},
- timeout: Constants.AXIOS_TIMEOUT
});
} catch (error) {
// Handle errors

MODIFY
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/CPOCommandsEndpoint.ts
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/CPOCommandsEndpoint.ts
@@ -329,15 +329,13 @@ export default class CPOCommandsEndpoint extends AbstractEndpoint {
detailedMessages: { payload }
});
// Call IOP
- let response: AxiosResponse;
try {
- response = await this.axiosInstance.post(responseUrl, payload,
+ await this.axiosInstance.post(responseUrl, payload,
{
headers: {
Authorization: `Token ${ocpiEndpoint.token}`,
'Content-Type': 'application/json'
},
- timeout: Constants.AXIOS_TIMEOUT
});
} catch (error) {
// Handle errors

MODIFY
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/CredentialsEndpoint.ts
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/CredentialsEndpoint.ts
@@ -164,7 +164,6 @@ export default class CredentialsEndpoint extends AbstractEndpoint {
headers: {
'Authorization': `Token ${ocpiEndpoint.token}`
},
- timeout: Constants.AXIOS_TIMEOUT
});
} catch (error) {
// Handle errors

MODIFY
src/utils/AxiosFactory.ts
src/utils/AxiosFactory.ts
import axios, { AxiosInstance } from 'axios';
-
import axiosRetry from 'axios-retry';
+import Constants from './Constants';
+
export default class AxiosFactory {
private static axiosInstance: AxiosInstance;
@@ -11,7 +12,10 @@ export default class AxiosFactory {
public static getAxiosInstance(): AxiosInstance {
AxiosFactory.setupAxiosInstance();
if (!AxiosFactory.axiosInstance) {
+ // Create
AxiosFactory.axiosInstance = axios.create();
+ // Time out
+ AxiosFactory.axiosInstance.defaults.timeout = Constants.AXIOS_TIMEOUT;
}
return AxiosFactory.axiosInstance;
}

Handle Axios timeout globally