mirror of
https://github.com/samuelthomas2774/nxapi.git
synced 2026-10-19 16:17:56 -05:00
Improve error messages, record error history for use limits
This commit is contained in:
@@ -9,6 +9,7 @@ import { AccountLogin, AccountLoginParameter, AccountToken, AccountTokenParamete
|
||||
import { f, FResult, HashMethod } from './f.js';
|
||||
import { generateAuthData, getNintendoAccountToken, getNintendoAccountUser, NintendoAccountSessionAuthorisation, NintendoAccountToken, NintendoAccountUser } from './na.js';
|
||||
import { ErrorResponse, ResponseSymbol } from './util.js';
|
||||
import { ErrorDescription, ErrorDescriptionSymbol, HasErrorDescription } from '../util/errors.js';
|
||||
|
||||
const debug = createDebug('nxapi:api:coral');
|
||||
|
||||
@@ -474,10 +475,21 @@ export default class CoralApi implements CoralApiInterface {
|
||||
}
|
||||
}
|
||||
|
||||
export class CoralErrorResponse extends ErrorResponse<CoralError> {
|
||||
export class CoralErrorResponse extends ErrorResponse<CoralError> implements HasErrorDescription {
|
||||
get status(): CoralStatus | null {
|
||||
return this.data?.status ?? null;
|
||||
}
|
||||
|
||||
get [ErrorDescriptionSymbol]() {
|
||||
if (this.status === CoralStatus.NSA_NOT_LINKED) {
|
||||
return new ErrorDescription('coral.nsa_not_linked', 'Your Nintendo Account is not linked to a Network Service Account (Nintendo Switch user).\n\nMake sure you are using the Nintendo Account linked to your Nintendo Switch console.');
|
||||
}
|
||||
if (this.status === CoralStatus.UPGRADE_REQUIRED) {
|
||||
return new ErrorDescription('coral.upgrade_required', 'The Coral (Nintendo Switch Online app) version used by nxapi is no longer supported by the Coral API.\n\nTry restarting nxapi and make sure nxapi is up to date.');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const na_client_settings = {
|
||||
|
||||
@@ -4,6 +4,7 @@ import { defineResponse, ErrorResponse, HasResponse } from './util.js';
|
||||
import createDebug from '../util/debug.js';
|
||||
import { JwtPayload } from '../util/jwt.js';
|
||||
import { timeoutSignal } from '../util/misc.js';
|
||||
import { ErrorDescription, ErrorDescriptionSymbol, HasErrorDescription } from '../util/errors.js';
|
||||
|
||||
const debug = createDebug('nxapi:api:na');
|
||||
|
||||
@@ -408,6 +409,14 @@ export interface NintendoAccountError {
|
||||
type: string;
|
||||
}
|
||||
|
||||
export class NintendoAccountAuthErrorResponse extends ErrorResponse<NintendoAccountAuthError> {}
|
||||
export class NintendoAccountAuthErrorResponse extends ErrorResponse<NintendoAccountAuthError> implements HasErrorDescription {
|
||||
get [ErrorDescriptionSymbol]() {
|
||||
if (this.data?.error === 'invalid_grant') {
|
||||
return new ErrorDescription('na.invalid_grant', 'Your Nintendo Account session token has expired or was revoked.\n\nYou need to sign in again.');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export class NintendoAccountErrorResponse extends ErrorResponse<NintendoAccountError> {}
|
||||
|
||||
Reference in New Issue
Block a user