Ignore errors from presence URLs and non-Nintendo API errors

This commit is contained in:
Samuel Elliott 2023-07-10 13:04:45 +01:00
parent dfb2a3eea7
commit bb45ee39f5
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6

View File

@ -12,6 +12,9 @@ import { DiscordPresence, DiscordPresencePlayTime, ErrorResult } from '../../dis
import { DiscordRpcClient } from '../../discord/rpc.js';
import SplatNet3Monitor, { getConfigFromAppConfig as getSplatNet3MonitorConfigFromAppConfig } from '../../discord/monitor/splatoon3.js';
import { ErrorDescription } from '../../util/errors.js';
import { CoralErrorResponse } from '../../api/coral.js';
import { NintendoAccountAuthErrorResponse, NintendoAccountErrorResponse } from '../../api/na.js';
import { InvalidNintendoAccountTokenError } from '../../common/auth/na.js';
const debug = createDebug('app:main:monitor');
@ -376,6 +379,10 @@ export class PresenceMonitorManager {
monitor: EmbeddedPresenceMonitor | EmbeddedProxyPresenceMonitor,
err: ErrorResponse<CoralError> | NodeJS.ErrnoException
): Promise<LoopResult> {
if (monitor instanceof EmbeddedProxyPresenceMonitor || checkShouldIgnorePresenceMonitorError(err)) {
return LoopResult.OK;
}
const {response} = await showErrorDialog({
message: err.name + ' updating presence monitor',
error: err,
@ -574,3 +581,31 @@ export class ElectronNotificationManager extends NotificationManager {
}).show();
}
}
function checkShouldIgnorePresenceMonitorError(err: Error): boolean {
// Invalid session token, the user needs to sign in again
if (err instanceof InvalidNintendoAccountTokenError) {
return false;
}
// Received error getting a Nintendo Account token; usually this means
// the session token is invalid and the user needs to sign in again
if (err instanceof NintendoAccountAuthErrorResponse && err.data) {
return false;
}
// Received error getting Nintendo Account user data
// This can only happen once when the app starts and there isn't a cached token
if (err instanceof NintendoAccountErrorResponse && err.data) {
return false;
}
// Received error from Coral (see CoralStatus in src/api/coral-types.ts)
// This usually should either not happen (e.g. BAD_REQUEST), is something the
// user needs to do (e.g. NSA_NOT_LINKED or UPGRADE_REQUIRED), or is permanent
if (err instanceof CoralErrorResponse && err.data) {
return false;
}
return true;
}