From 53a7da7a1a089086fb9e3e49f56e9887e77c5078 Mon Sep 17 00:00:00 2001 From: Eric Seidel Date: Thu, 14 Mar 2024 05:17:27 +0000 Subject: [PATCH] fix: guard against ship in transit exception? Not sure what is causing this. Might be 500s on the server side, or might be incorrect local predictions? --- packages/cli/lib/nav/navigation.dart | 19 +++++++++++++++---- packages/cli/lib/net/exceptions.dart | 10 ++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/packages/cli/lib/nav/navigation.dart b/packages/cli/lib/nav/navigation.dart index eed33490..98f7f669 100644 --- a/packages/cli/lib/nav/navigation.dart +++ b/packages/cli/lib/nav/navigation.dart @@ -358,15 +358,26 @@ Future continueNavigationIfNeeded( } } } - return NavResult._wait( - await navigateToLocalWaypointAndLog( + final DateTime waitUntil; + try { + waitUntil = await navigateToLocalWaypointAndLog( db, api, caches.systems, ship, actionEnd, - ), - ); + ); + } on ApiException catch (e) { + if (isShipInTransitException(e)) { + shipErr(ship, 'Ship is in transit, cannot navigate'); + throw const JobException( + 'Already in transit!?', + Duration(minutes: 10), + ); + } + rethrow; + } + return NavResult._wait(waitUntil); case RouteActionType.navDrift: return NavResult._wait( await navigateToLocalWaypointAndLog( diff --git a/packages/cli/lib/net/exceptions.dart b/packages/cli/lib/net/exceptions.dart index 8555bc98..2e02251f 100644 --- a/packages/cli/lib/net/exceptions.dart +++ b/packages/cli/lib/net/exceptions.dart @@ -197,3 +197,13 @@ int? neededCreditsFromPurchaseShipException(ApiException e) { bool isConstructionRequirementsMet(ApiException e) { return isAPIExceptionWithCode(e, 4801); } + +// ApiException 400: {"error":{"message":"Ship is currently in-transit from +// X1-TA36-C36 to X1-TA36-C37 and arrives in 26 seconds.","code":4214, +// "data":{"departureSymbol":"X1-TA36-C36","destinationSymbol":"X1-TA36-C37", +// "arrival":"2024-03-14T03:15:02.404Z","departureTime": +// "2024-03-14T03:14:35.404Z","secondsToArrival":26}}} +/// Returns true if the exception is a ship in transit exception. +bool isShipInTransitException(ApiException e) { + return isAPIExceptionWithCode(e, 4214); +}