processCommonClientExceptions function
void
processCommonClientExceptions(
- CommandLogger logger,
- String baseCommand,
- Exception e,
- StackTrace stackTrace,
If the exception is a common client exception, process it by displaying relevant messages to the user and throwing an ErrorExitException.
If this function returns normally, no action was taken and the caller needs to continue processing the exception.
Implementation
void processCommonClientExceptions(
CommandLogger logger,
String baseCommand,
Exception e,
StackTrace stackTrace,
) {
final exitException = commonClientExceptionExit(e, stackTrace);
if (exitException == null) return;
switch (e) {
case ServerpodClientUnauthorized():
logger.error(
'The credentials for this session seem to no longer be valid.',
);
logger.terminalCommand(
message: 'Run the following commands to re-authenticate:',
'$baseCommand auth logout',
);
logger.terminalCommand('$baseCommand auth login');
case UnauthorizedException():
logger.error('You are not authorized to perform this action.');
case ProcurementDeniedException():
final baseUrl = getConsoleBaseUrl();
if (e.message.contains('no valid payment method')) {
final setupUrl = '$baseUrl/project/create';
logger.error(
"You need a payment method!",
hint: 'To set up your account, visit: $setupUrl\n',
newParagraph: true,
);
} else {
final projectsUrl = '$baseUrl/project';
logger.error(
e.message,
hint: 'To see your account, visit: $projectsUrl\n',
newParagraph: true,
);
}
case NotFoundException():
logger.error('The requested resource did not exist.', hint: e.message);
}
throw exitException;
}