Skip to content

Commit

Permalink
core: more explicit return
Browse files Browse the repository at this point in the history
make sure handle() is called only when not recoverable

Signed-off-by: Pierre-Etienne Bougué <[email protected]>
  • Loading branch information
bougue-pe committed Nov 15, 2024
1 parent e0e10d5 commit 401947e
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class PathfindingBlocksEndpointV2(private val infraManager: InfraManager) : Take

override fun act(req: Request): Response {
val recorder = DiagnosticRecorderImpl(false)
return try {
try {
val body = RqPrint(req).printBody()
val request =
pathfindingRequestAdapter.fromJson(body)
Expand All @@ -57,17 +57,17 @@ class PathfindingBlocksEndpointV2(private val infraManager: InfraManager) : Take
val infra = infraManager.getInfra(request.infra, request.expectedVersion, recorder)
val res = runPathfinding(infra, request)
pathfindingLogger.info("Success")
RsJson(RsWithBody(pathfindingResponseAdapter.toJson(res)))
return RsJson(RsWithBody(pathfindingResponseAdapter.toJson(res)))
} catch (error: NoPathFoundException) {
pathfindingLogger.info("No path found")
RsJson(RsWithBody(pathfindingResponseAdapter.toJson(error.response)))
return RsJson(RsWithBody(pathfindingResponseAdapter.toJson(error.response)))
} catch (ex: Throwable) {
if (ex is OSRDError && ex.osrdErrorType.isRecoverable) {
pathfindingLogger.info("Pathfinding failed: ${ex.message}")
val response = PathfindingFailed(ex)
RsJson(RsWithBody(pathfindingResponseAdapter.toJson(response)))
return RsJson(RsWithBody(pathfindingResponseAdapter.toJson(response)))
}
ExceptionHandler.handle(ex)
return ExceptionHandler.handle(ex)
}
}
}
Expand Down

0 comments on commit 401947e

Please sign in to comment.