return { valid: true }
} catch (error) {
return {
- reason: `Certificate parsing failed: ${error instanceof Error ? error.message : 'Unknown error'}`,
+ reason: `Certificate parsing failed: ${getErrorMessage(error)}`,
valid: false,
}
}
OCPPVersion,
type RequestParams,
} from '../../../types/index.js'
-import { generateUUID, logger } from '../../../utils/index.js'
+import { generateUUID, getErrorMessage, logger } from '../../../utils/index.js'
import { OCPPRequestService } from '../OCPPRequestService.js'
import { createPayloadValidatorMap, isRequestCommandSupported } from '../OCPPServiceUtils.js'
import { generatePkcs10Csr } from './Asn1DerUtils.js'
csr = generatePkcs10Csr(stationId, orgName)
} catch (error) {
- const errorMsg = `Failed to generate CSR: ${error instanceof Error ? error.message : 'Unknown error'}`
+ const errorMsg = `Failed to generate CSR: ${getErrorMessage(error)}`
logger.error(
`${chargingStation.logPrefix()} ${moduleName}.buildRequestPayload: ${errorMsg}`
)
RequestCommand,
StandardParametersKey,
} from '../../../../types/index.js'
-import { convertToBoolean, logger, truncateId } from '../../../../utils/index.js'
+import { convertToBoolean, getErrorMessage, logger, truncateId } from '../../../../utils/index.js'
import {
AuthContext,
AuthenticationMethod,
return {
additionalInfo: {
connectorId,
- error: error instanceof Error ? error.message : 'Unknown error',
+ error: getErrorMessage(error),
transactionId,
},
isOffline: false,
OCPP20RequiredVariableName,
OCPPVersion,
} from '../../../../types/index.js'
-import { logger, truncateId } from '../../../../utils/index.js'
+import { getErrorMessage, logger, truncateId } from '../../../../utils/index.js'
import {
AuthContext,
AuthenticationMethod,
return {
additionalInfo: {
connectorId,
- error: error instanceof Error ? error.message : 'Unknown error',
+ error: getErrorMessage(error),
transactionId,
},
isOffline: false,
import type { AuthCache, CacheStats } from '../interfaces/OCPPAuthService.js'
import type { AuthorizationResult } from '../types/AuthTypes.js'
-import { logger, truncateId } from '../../../../utils/index.js'
+import { Constants, logger, truncateId } from '../../../../utils/index.js'
import { AuthorizationStatus } from '../types/AuthTypes.js'
const moduleName = 'InMemoryAuthCache'
* @param options.cleanupIntervalSeconds - Periodic cleanup interval in seconds (default: 300, 0 to disable)
* @param options.defaultTtl - Default TTL in seconds (default: 3600)
* @param options.maxAbsoluteLifetimeMs - Absolute lifetime cap in milliseconds (default: 86400000)
- * @param options.maxEntries - Maximum number of cache entries (default: 1000)
+ * @param options.maxEntries - Maximum number of cache entries (default: Constants.DEFAULT_AUTH_CACHE_MAX_ENTRIES)
* @param options.rateLimit - Rate limiting configuration
* @param options.rateLimit.enabled - Enable rate limiting (default: false)
* @param options.rateLimit.maxRequests - Max requests per window (default: 10)
this.defaultTtl = options?.defaultTtl ?? 3600 // 1 hour default
this.maxAbsoluteLifetimeMs =
options?.maxAbsoluteLifetimeMs ?? InMemoryAuthCache.DEFAULT_MAX_ABSOLUTE_LIFETIME_MS
- this.maxEntries = Math.max(1, options?.maxEntries ?? 1000)
+ this.maxEntries = Math.max(1, options?.maxEntries ?? Constants.DEFAULT_AUTH_CACHE_MAX_ENTRIES)
this.rateLimit = {
enabled: options?.rateLimit?.enabled ?? false,
maxRequests: options?.rateLimit?.maxRequests ?? 10, // 10 requests per window
import { OCPPError } from '../../../../exception/index.js'
import { ErrorType, OCPPVersion } from '../../../../types/index.js'
+import { Constants } from '../../../../utils/index.js'
import { OCPP16AuthAdapter } from '../adapters/OCPP16AuthAdapter.js'
import { OCPP20AuthAdapter } from '../adapters/OCPP20AuthAdapter.js'
import { InMemoryAuthCache } from '../cache/InMemoryAuthCache.js'
static createAuthCache (config: AuthConfiguration): AuthCache {
return new InMemoryAuthCache({
defaultTtl: config.authorizationCacheLifetime ?? 3600,
- maxEntries: config.maxCacheEntries ?? 1000,
+ maxEntries: config.maxCacheEntries ?? Constants.DEFAULT_AUTH_CACHE_MAX_ENTRIES,
})
}
import { OCPPError } from '../../../../exception/index.js'
import { ErrorType, OCPPVersion } from '../../../../types/index.js'
import {
+ Constants,
convertToDate,
ensureError,
getErrorMessage,
certificateValidationStrict: false,
localAuthListEnabled: true,
localPreAuthorize: false,
- maxCacheEntries: 1000,
+ maxCacheEntries: Constants.DEFAULT_AUTH_CACHE_MAX_ENTRIES,
ocppVersion: this.chargingStation.stationInfo?.ocppVersion,
offlineAuthorizationEnabled: true,
remoteAuthorization: true,
type UIServerConfiguration,
type UUIDv4,
} from '../../types/index.js'
-import { generateUUID, logger } from '../../utils/index.js'
+import { generateUUID, getErrorMessage, logger } from '../../utils/index.js'
import { AbstractUIServer } from './AbstractUIServer.js'
import {
mcpToolSchemas,
} catch (error: unknown) {
logger.error(`${this.logPrefix(moduleName, 'handleMcpRequest')} MCP transport error:`, error)
const isBadRequest =
- error instanceof SyntaxError ||
- (error instanceof Error && error.message.includes('Payload too large'))
+ error instanceof SyntaxError || getErrorMessage(error).includes('Payload too large')
this.sendErrorResponse(res, isBadRequest ? 400 : 500)
}
}
clearTimeout(pending.timeout)
this.pendingMcpRequests.delete(uuid)
}
- resolve(
- UIMCPServer.createToolErrorResponse(
- error instanceof Error ? error.message : String(error)
- )
- )
+ resolve(UIMCPServer.createToolErrorResponse(getErrorMessage(error)))
})
})
}
extractTimeSeriesValues,
formatDurationSeconds,
generateUUID,
+ getErrorMessage,
JSONStringify,
logger,
logPrefix,
try {
performance.measure(name, markId)
} catch (error) {
- if (error instanceof Error && error.message.includes('performance mark has not been set')) {
+ if (getErrorMessage(error).includes('performance mark has not been set')) {
/* Ignore */
} else {
throw error
static readonly DEFAULT_ATG_WAIT_TIME = 1000 // Ms
+ static readonly DEFAULT_AUTH_CACHE_MAX_ENTRIES = 1000
+
static readonly DEFAULT_BOOT_NOTIFICATION_INTERVAL = 60000 // Ms
static readonly DEFAULT_CIRCULAR_BUFFER_CAPACITY = 386