Skip to content

Commit

Permalink
feat : Explicit connection error
Browse files Browse the repository at this point in the history
  • Loading branch information
erwanmarimpouy committed Jul 8, 2024
1 parent 65bf0e6 commit 2dd6255
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ class OcppWampServerApp(
fun sendBlocking(ocppId: CSOcppId, message: WampMessage, startedCallAt: Instant = Clock.System.now()): WampMessage =
getChargingStationConnection(ocppId).sendBlocking(message, startedCallAt)

// Throws NoConnectionException when no connection is found for the specified ocpp id
private fun getChargingStationConnection(ocppId: CSOcppId): ChargingStationConnection {
var backOffRetryMs = 10L
var backOffRetryAttempts = 5
Expand All @@ -253,9 +254,8 @@ class OcppWampServerApp(
backOffRetryMs *= 2
connection = connections[ocppId]
}
return connection ?: throw IllegalStateException("no connection to $ocppId")
return connection ?: throw NoConnectionException("no connection to $ocppId")
}

fun getChargingStationOcppVersion(ocppId: CSOcppId): OcppVersion =
getChargingStationConnection(ocppId).ocppVersion

Expand Down Expand Up @@ -305,5 +305,7 @@ class OcppWampServerApp(
}
}

class NoConnectionException(e: String) : IllegalStateException(e)

private fun Throwable.isConnectionReset(): Boolean =
this is SocketException && this.message.equals("Connection reset")

0 comments on commit 2dd6255

Please sign in to comment.