Removed useless HTTP checks
MODIFY
src/client/ocpi/CpoOCPIClient.ts
src/client/ocpi/CpoOCPIClient.ts
@@ -88,14 +88,6 @@ export default class CpoOCPIClient extends OCPIClient {
// Handle errors
Utils.handleAxiosError(error, tokensUrl, ServerAction.OCPI_PULL_TOKENS, MODULE_NAME, 'pullTokens');
}
- // Check response
- if (response.status !== 200 || !response.data) {
- throw new BackendError({
- action: ServerAction.OCPI_PULL_TOKENS,
- message: `Invalid response code ${response.status} from Pull tokens`,
- module: MODULE_NAME, method: 'pullTokens',
- });
- }
if (!response.data.data) {
throw new BackendError({
action: ServerAction.OCPI_PULL_TOKENS,
@@ -187,14 +179,6 @@ export default class CpoOCPIClient extends OCPIClient {
// Handle errors
Utils.handleAxiosError(error, tokensUrl, ServerAction.OCPI_AUTHORIZE_TOKEN, MODULE_NAME, 'authorizeToken');
}
- if (response.status !== 200 || !response.data) {
- throw new BackendError({
- action: ServerAction.OCPI_AUTHORIZE_TOKEN,
- message: `Post authorize failed with status ${response.status}`,
- module: MODULE_NAME, method: 'authorizeToken',
- detailedMessages: { payload: response.data }
- });
- }
if (!response.data.data) {
throw new BackendError({
action: ServerAction.OCPI_AUTHORIZE_TOKEN,
@@ -343,14 +327,6 @@ export default class CpoOCPIClient extends OCPIClient {
// Handle errors
Utils.handleAxiosError(error, sessionsUrl, ServerAction.OCPI_PUSH_SESSIONS, MODULE_NAME, 'updateSession');
}
- if (response.status !== 200 || !response.data) {
- throw new BackendError({
- action: ServerAction.OCPI_PUSH_SESSIONS,
- message: `Patch Session failed with status ${response.status}`,
- module: MODULE_NAME, method: 'updateSession',
- detailedMessages: { payload: response.data }
- });
- }
Logging.logDebug({
tenantID: this.tenant.id,
action: ServerAction.OCPI_PUSH_SESSIONS,
@@ -408,14 +384,6 @@ export default class CpoOCPIClient extends OCPIClient {
// Handle errors
Utils.handleAxiosError(error, tokensUrl, ServerAction.OCPI_PUSH_SESSIONS, MODULE_NAME, 'stopSession');
}
- if (response.status !== 200 || !response.data) {
- throw new BackendError({
- action: ServerAction.OCPI_PUSH_SESSIONS,
- message: `Stop Session failed with status ${response.status}`,
- module: MODULE_NAME, method: 'stopSession',
- detailedMessages: { payload: response.data }
- });
- }
Logging.logDebug({
tenantID: this.tenant.id,
action: ServerAction.OCPI_PUSH_SESSIONS,
@@ -483,14 +451,6 @@ export default class CpoOCPIClient extends OCPIClient {
// Handle errors
Utils.handleAxiosError(error, cdrsUrl, ServerAction.OCPI_PUSH_CDRS, MODULE_NAME, 'stopSession');
}
- if (response.status !== 200 || !response.data) {
- throw new BackendError({
- action: ServerAction.OCPI_PUSH_CDRS,
- message: `Post cdr failed with status ${response.status}`,
- module: MODULE_NAME, method: 'postCdr',
- detailedMessages: { payload: response.data }
- });
- }
Logging.logDebug({
tenantID: this.tenant.id,
action: ServerAction.OCPI_PUSH_CDRS,
@@ -608,14 +568,6 @@ export default class CpoOCPIClient extends OCPIClient {
// Handle errors
Utils.handleAxiosError(error, fullUrl, ServerAction.OCPI_PATCH_STATUS, MODULE_NAME, 'patchEVSEStatus');
}
- // Check response
- if (!response.data) {
- throw new BackendError({
- action: ServerAction.OCPI_PATCH_STATUS,
- message: `Patch EVSE Status failed with status ${response.status}`,
- module: MODULE_NAME, method: 'patchEVSEStatus',
- });
- }
}
async checkCdr(transaction: Transaction): Promise<boolean> {
@@ -650,7 +602,6 @@ export default class CpoOCPIClient extends OCPIClient {
Utils.handleAxiosError(error, `${cdrsUrl}/${transaction.ocpiData.cdr.id}`,
ServerAction.OCPI_CHECK_CDRS, MODULE_NAME, 'checkCdr');
}
- if (response.status === 200 && response.data) {
Logging.logDebug({
tenantID: this.tenant.id,
action: ServerAction.OCPI_CHECK_CDRS,
@@ -675,7 +626,6 @@ export default class CpoOCPIClient extends OCPIClient {
await TransactionStorage.saveTransaction(this.tenant.id, transaction);
return true;
}
- }
throw new BackendError({
action: ServerAction.OCPI_CHECK_CDRS,
message: `Invalid response from Check cdr at ${cdrsUrl}/${transaction.ocpiData.cdr.id}`,
@@ -714,7 +664,6 @@ export default class CpoOCPIClient extends OCPIClient {
// Handle errors
Utils.handleAxiosError(error, sessionsUrl, ServerAction.OCPI_CHECK_SESSIONS, MODULE_NAME, 'checkSession');
}
- if (response.status === 200 && response.data) {
Logging.logDebug({
tenantID: this.tenant.id,
action: ServerAction.OCPI_CHECK_SESSIONS,
@@ -728,7 +677,6 @@ export default class CpoOCPIClient extends OCPIClient {
await TransactionStorage.saveTransaction(this.tenant.id, transaction);
return true;
}
- }
throw new BackendError({
action: ServerAction.OCPI_CHECK_CDRS,
message: `Invalid response from Check session at ${sessionsUrl}`,
@@ -840,7 +788,6 @@ export default class CpoOCPIClient extends OCPIClient {
// Handle errors
Utils.handleAxiosError(error, locationUrl, ServerAction.OCPI_CHECK_LOCATIONS, MODULE_NAME, 'checkLocation');
}
- if (response.status === 200 && response.data) {
Logging.logDebug({
tenantID: this.tenant.id,
action: ServerAction.OCPI_CHECK_LOCATIONS,
@@ -852,7 +799,6 @@ export default class CpoOCPIClient extends OCPIClient {
if (checkedLocation) {
return true;
}
- }
throw new BackendError({
action: ServerAction.OCPI_CHECK_LOCATIONS,
message: 'Invalid response from Check location',

MODIFY
src/client/ocpi/EmspOCPIClient.ts
src/client/ocpi/EmspOCPIClient.ts
@@ -182,22 +182,6 @@ export default class EmspOCPIClient extends OCPIClient {
// Handle errors
Utils.handleAxiosError(error, locationsUrl, ServerAction.OCPI_PULL_LOCATIONS, MODULE_NAME, 'pullLocations');
}
- // Check response
- if (response.status !== 200 || !response.data) {
- throw new BackendError({
- action: ServerAction.OCPI_PULL_LOCATIONS,
- message: `Invalid response code ${response.status} from Get locations`,
- module: MODULE_NAME, method: 'pullLocations',
- });
- }
- if (!response.data.data) {
- throw new BackendError({
- action: ServerAction.OCPI_PULL_LOCATIONS,
- message: 'Invalid response from Get locations',
- module: MODULE_NAME, method: 'pullLocations',
- detailedMessages: { response: response.data }
- });
- }
for (const location of response.data.data) {
try {
await this.processLocation(location, company, sites.result);
@@ -257,22 +241,6 @@ export default class EmspOCPIClient extends OCPIClient {
// Handle errors
Utils.handleAxiosError(error, sessionsUrl, ServerAction.OCPI_PULL_SESSIONS, MODULE_NAME, 'pullSessions');
}
- // Check response
- if (response.status !== 200 || !response.data) {
- throw new BackendError({
- action: ServerAction.OCPI_PULL_SESSIONS,
- message: `Invalid response code ${response.status} from Get sessions`,
- module: MODULE_NAME, method: 'pullSessions',
- });
- }
- if (!response.data.data) {
- throw new BackendError({
- action: ServerAction.OCPI_PULL_SESSIONS,
- message: 'Invalid response from Get sessions',
- module: MODULE_NAME, method: 'pullSessions',
- detailedMessages: { response: response.data }
- });
- }
for (const session of response.data.data) {
try {
await OCPISessionsService.updateTransaction(this.tenant.id, session);
@@ -333,23 +301,6 @@ export default class EmspOCPIClient extends OCPIClient {
// Handle errors
Utils.handleAxiosError(error, cdrsUrl, ServerAction.OCPI_PULL_CDRS, MODULE_NAME, 'pullCdrs');
}
- // Check response
- if (response.status !== 200 || !response.data) {
- throw new BackendError({
- action: ServerAction.OCPI_PULL_CDRS,
- message: `Get cdrs failed with status ${response.status}`,
- module: MODULE_NAME, method: 'pullCdrs',
- detailedMessages: { response: response.data }
- });
- }
- if (!response.data.data) {
- throw new BackendError({
- action: ServerAction.OCPI_PULL_CDRS,
- message: 'Invalid response from Get cdrs',
- module: MODULE_NAME, method: 'pullCdrs',
- detailedMessages: { response: response.data }
- });
- }
for (const cdr of response.data.data) {
try {
await OCPISessionsService.processCdr(this.tenant.id, cdr);
@@ -505,7 +456,6 @@ export default class EmspOCPIClient extends OCPIClient {
// Handle errors
Utils.handleAxiosError(error, fullUrl, ServerAction.OCPI_CHECK_TOKENS, MODULE_NAME, 'getToken');
}
- if (response.status === 200 && response.data) {
Logging.logDebug({
tenantID: this.tenant.id,
action: ServerAction.OCPI_CHECK_LOCATIONS,
@@ -517,7 +467,6 @@ export default class EmspOCPIClient extends OCPIClient {
if (checkedToken) {
return true;
}
- }
// Check response
if (!response.data) {
throw new BackendError({
@@ -560,15 +509,6 @@ export default class EmspOCPIClient extends OCPIClient {
// Handle errors
Utils.handleAxiosError(error, fullUrl, ServerAction.OCPI_PUSH_TOKENS, MODULE_NAME, 'pushToken');
}
- // Check response
- if (!response.data) {
- throw new BackendError({
- action: ServerAction.OCPI_PUSH_TOKENS,
- message: `Push token failed with status ${JSON.stringify(response)}`,
- module: MODULE_NAME, method: 'pushToken',
- detailedMessages: { response: response.data }
- });
- }
return this.checkToken(token.uid);
}
@@ -635,23 +575,6 @@ export default class EmspOCPIClient extends OCPIClient {
// Handle errors
Utils.handleAxiosError(error, commandUrl, ServerAction.OCPI_START_SESSION, MODULE_NAME, 'remoteStartSession');
}
- // Check response
- if (!response.data) {
- throw new BackendError({
- action: ServerAction.OCPI_START_SESSION,
- message: `OCPI Remote Start session failed with status ${JSON.stringify(response)}`,
- module: MODULE_NAME, method: 'remoteStartSession',
- detailedMessages: { response: response.data }
- });
- }
- if (!response.data.data) {
- throw new BackendError({
- action: ServerAction.OCPI_START_SESSION,
- message: 'OCPI Remote Start session response is invalid',
- module: MODULE_NAME, method: 'remoteStartSession',
- detailedMessages: { response: response.data }
- });
- }
Logging.logDebug({
tenantID: this.tenant.id,
action: ServerAction.OCPI_START_SESSION,
@@ -702,23 +625,6 @@ export default class EmspOCPIClient extends OCPIClient {
// Handle errors
Utils.handleAxiosError(error, commandUrl, ServerAction.OCPI_STOP_SESSION, MODULE_NAME, 'remoteStopSession');
}
- // Check response
- if (!response.data) {
- throw new BackendError({
- action: ServerAction.OCPI_STOP_SESSION,
- message: `OCPI Remote Stop session failed with status ${response.status}`,
- module: MODULE_NAME, method: 'remoteStopSession',
- detailedMessages: { response: response.data }
- });
- }
- if (!response.data.data) {
- throw new BackendError({
- action: ServerAction.OCPI_STOP_SESSION,
- message: 'OCPI Remote Stop session response is invalid',
- module: MODULE_NAME, method: 'remoteStopSession',
- detailedMessages: { response: response.data }
- });
- }
Logging.logDebug({
tenantID: this.tenant.id,
action: ServerAction.OCPI_STOP_SESSION,

MODIFY
src/client/ocpi/OCPIClient.ts
src/client/ocpi/OCPIClient.ts
@@ -182,15 +182,6 @@ export default abstract class OCPIClient {
// Handle errors
Utils.handleAxiosError(error, this.ocpiEndpoint.baseUrl, ServerAction.OCPI_GET_VERSIONS, MODULE_NAME, 'getVersions');
}
- // Check response
- if (!response.data || !response.data.data) {
- throw new BackendError({
- action: ServerAction.OCPI_GET_VERSIONS,
- message: `Invalid response from GET ${this.ocpiEndpoint.baseUrl}`,
- module: MODULE_NAME, method: 'getVersions',
- detailedMessages: { response: response.data }
- });
- }
return response;
}
@@ -217,15 +208,6 @@ export default abstract class OCPIClient {
// Handle errors
Utils.handleAxiosError(error, this.ocpiEndpoint.versionUrl, ServerAction.OCPI_GET_VERSIONS, MODULE_NAME, 'getServices');
}
- // Check response
- if (!response.data || !response.data.data) {
- throw new BackendError({
- action: ServerAction.OCPI_GET_VERSIONS,
- message: `Invalid response from GET ${this.ocpiEndpoint.versionUrl}`,
- module: MODULE_NAME, method: 'getServices',
- detailedMessages: { response: response.data }
- });
- }
return response;
}
@@ -254,15 +236,6 @@ export default abstract class OCPIClient {
// Handle errors
Utils.handleAxiosError(error, credentialsUrl, ServerAction.OCPI_POST_CREDENTIALS, MODULE_NAME, 'deleteCredentials');
}
- // Check response
- if (!response.data) {
- throw new BackendError({
- action: ServerAction.OCPI_POST_CREDENTIALS,
- message: 'Invalid response from delete credentials',
- module: MODULE_NAME, method: 'deleteCredentials',
- detailedMessages: { response: response.data }
- });
- }
return response;
}
@@ -296,15 +269,6 @@ export default abstract class OCPIClient {
// Handle errors
Utils.handleAxiosError(error, credentialsUrl, ServerAction.OCPI_POST_CREDENTIALS, MODULE_NAME, 'postCredentials');
}
- // Check response
- if (!response.data) {
- throw new BackendError({
- action: ServerAction.OCPI_POST_CREDENTIALS,
- message: 'Invalid response from post credentials',
- module: MODULE_NAME, method: 'postCredentials',
- detailedMessages: { response: response.data }
- });
- }
return response;
}

MODIFY
src/integration/asset/schneider/SchneiderAssetIntegration.ts
src/integration/asset/schneider/SchneiderAssetIntegration.ts
@@ -44,7 +44,6 @@ export default class SchneiderAssetIntegration extends AssetIntegration<AssetSet
// Handle errors
Utils.handleAxiosError(error, request, ServerAction.RETRIEVE_ASSET_CONSUMPTION, MODULE_NAME, 'retrieveConsumption');
}
- if (response.data && response.data.length > 0) {
Logging.logDebug({
tenantID: this.tenantID,
source: Constants.CENTRAL_SERVER,
@@ -54,7 +53,6 @@ export default class SchneiderAssetIntegration extends AssetIntegration<AssetSet
detailedMessages: { response: response.data }
});
return this.filterConsumptionRequest(asset, response.data);
- }
} catch (error) {
throw new BackendError({
source: Constants.CENTRAL_SERVER,
@@ -130,11 +128,9 @@ export default class SchneiderAssetIntegration extends AssetIntegration<AssetSet
// Handle errors
Utils.handleAxiosError(error, `${this.connection.url}/GetToken`, ServerAction.CHECK_ASSET_CONNECTION, MODULE_NAME, 'connect');
}
- // Set Token
- if (response.data && response.data.access_token) {
+ // Return the Token
return response.data.access_token;
}
- }
private getCredentialURLParams(): URLSearchParams {
const params = new URLSearchParams();

MODIFY
src/integration/car/ev-database/EVDabaseCarIntegration.ts
src/integration/car/ev-database/EVDabaseCarIntegration.ts
@@ -38,14 +38,6 @@ export default class EVDabaseCarIntegration extends CarIntegration {
Utils.handleAxiosError(error, evDatabaseConfig.url + '/' + evDatabaseConfig.key, ServerAction.SYNCHRONIZE_CAR_CATALOGS, MODULE_NAME, 'getCarCatalogs');
}
const carCatalogs: CarCatalog[] = [];
- if (response.status !== 200) {
- throw new BackendError({
- source: Constants.CENTRAL_SERVER,
- message: 'Error occurred while trying to retrieve the cars from EVDatabase',
- module: MODULE_NAME, method: 'getCarCatalogs',
- action: ServerAction.SYNCHRONIZE_CAR_CATALOGS,
- });
- }
// Build result
for (const data of response.data) {
const chargeStandardTables: CarCatalogConverter[] = [];

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
@@ -343,15 +343,6 @@ export default class CPOCommandsEndpoint extends AbstractEndpoint {
// Handle errors
Utils.handleAxiosError(error, responseUrl, action, MODULE_NAME, 'sendCommandResponse');
}
- // Check response
- if (response.status !== 200 || !response.data) {
- throw new BackendError({
- action: action,
- message: `Post send command response failed with status ${response.status}`,
- module: MODULE_NAME, method: 'sendCommandResponse',
- detailedMessages: { payload: response.data }
- });
- }
}
}

Removed useless HTTP checks