Fix error handling when using a presence URL

This commit is contained in:
Samuel Elliott 2022-10-31 16:49:12 +00:00
parent 1a25639440
commit f1ae5a7ea2
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
2 changed files with 26 additions and 13 deletions

View File

@ -179,21 +179,28 @@ export class ZncNotifications extends Loop {
}
async handleError(err: ErrorResponse<CoralErrorResponse> | NodeJS.ErrnoException): Promise<LoopResult> {
if ('code' in err && (err as any).type === 'system' && err.code === 'ETIMEDOUT') {
debug('Request timed out, waiting %ds before retrying', this.update_interval, err);
return handleError(err, this);
}
}
return LoopResult.OK;
} else if ('code' in err && (err as any).type === 'system' && err.code === 'ENOTFOUND') {
debug('Request error, waiting %ds before retrying', this.update_interval, err);
export async function handleError(
err: ErrorResponse<CoralErrorResponse> | NodeJS.ErrnoException,
loop: Loop,
): Promise<LoopResult> {
if ('code' in err && (err as any).type === 'system' && err.code === 'ETIMEDOUT') {
debug('Request timed out, waiting %ds before retrying', loop.update_interval, err);
return LoopResult.OK;
} else if ('code' in err && (err as any).type === 'system' && err.code === 'EAI_AGAIN') {
debug('Request error - name resolution failed, waiting %ds before retrying', this.update_interval, err);
return LoopResult.OK;
} else if ('code' in err && (err as any).type === 'system' && err.code === 'ENOTFOUND') {
debug('Request error, waiting %ds before retrying', loop.update_interval, err);
return LoopResult.OK;
} else {
throw err;
}
return LoopResult.OK;
} else if ('code' in err && (err as any).type === 'system' && err.code === 'EAI_AGAIN') {
debug('Request error - name resolution failed, waiting %ds before retrying', loop.update_interval, err);
return LoopResult.OK;
} else {
throw err;
}
}

View File

@ -2,7 +2,7 @@ import createDebug from 'debug';
import { DiscordRpcClient, findDiscordRpcClient } from '../discord/rpc.js';
import { getDiscordPresence, getInactiveDiscordPresence } from '../discord/util.js';
import { DiscordPresencePlayTime, DiscordPresenceContext, DiscordPresence, ExternalMonitorConstructor, ExternalMonitor, ErrorResult } from '../discord/types.js';
import { EmbeddedSplatNet2Monitor, ZncNotifications } from './notify.js';
import { EmbeddedSplatNet2Monitor, handleError, ZncNotifications } from './notify.js';
import { getPresenceFromUrl } from '../api/znc-proxy.js';
import { ActiveEvent, CurrentUser, Friend, Game, Presence, PresenceState, CoralErrorResponse } from '../api/coral-types.js';
import { ErrorResponse } from '../api/util.js';
@ -604,4 +604,10 @@ export class ZncProxyDiscordPresence extends Loop {
monitor.disable();
}
}
async handleError(err: ErrorResponse<CoralErrorResponse> | NodeJS.ErrnoException): Promise<LoopResult> {
this.discord.onError(err);
return handleError(err, this);
}
}