Skip to content

Commit

Permalink
fix: guard against ship in transit exception?
Browse files Browse the repository at this point in the history
Not sure what is causing this.  Might be 500s on the server side, or might be incorrect local predictions?
  • Loading branch information
eseidel committed Mar 14, 2024
1 parent e80a6cd commit 53a7da7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
19 changes: 15 additions & 4 deletions packages/cli/lib/nav/navigation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -358,15 +358,26 @@ Future<NavResult> 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(
Expand Down
10 changes: 10 additions & 0 deletions packages/cli/lib/net/exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 53a7da7

Please sign in to comment.