mirror of
https://github.com/samuelthomas2774/nxapi.git
synced 2026-09-07 02:45:09 -05:00
Format response data in error messages
This commit is contained in:
@@ -29,7 +29,7 @@ export async function getNintendoAccountSessionToken(code: string, verifier: str
|
||||
const token = await response.json() as NintendoAccountSessionToken | NintendoAccountError;
|
||||
|
||||
if ('errorCode' in token) {
|
||||
throw new ErrorResponse('[na] + ' + token.detail, response, token);
|
||||
throw new ErrorResponse('[na] ' + token.detail, response, token);
|
||||
}
|
||||
|
||||
debug('Got Nintendo Account session token', token);
|
||||
@@ -59,7 +59,7 @@ export async function getNintendoAccountToken(token: string, client_id: string)
|
||||
const nintendoAccountToken = await response.json() as NintendoAccountToken | NintendoAccountError;
|
||||
|
||||
if ('errorCode' in nintendoAccountToken) {
|
||||
throw new ErrorResponse('[na] + ' + nintendoAccountToken.detail, response, nintendoAccountToken);
|
||||
throw new ErrorResponse('[na] ' + nintendoAccountToken.detail, response, nintendoAccountToken);
|
||||
}
|
||||
|
||||
debug('Got Nintendo Account token', nintendoAccountToken);
|
||||
@@ -85,7 +85,7 @@ export async function getNintendoAccountUser(token: NintendoAccountToken) {
|
||||
const user = await response.json() as NintendoAccountUser | NintendoAccountError;
|
||||
|
||||
if ('errorCode' in user) {
|
||||
throw new ErrorResponse('[na] + ' + user.detail, response, user);
|
||||
throw new ErrorResponse('[na] ' + user.detail, response, user);
|
||||
}
|
||||
|
||||
debug('Got Nintendo Account user info', user);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import * as util from 'node:util';
|
||||
import { Response as NodeFetchResponse } from 'node-fetch';
|
||||
|
||||
export class ErrorResponse<T = unknown> extends Error {
|
||||
@@ -19,6 +20,19 @@ export class ErrorResponse<T = unknown> extends Error {
|
||||
} else if (typeof body !== 'undefined') {
|
||||
this.data = body;
|
||||
}
|
||||
|
||||
const stack = this.stack ?? (this.name + ': ' + message);
|
||||
const lines = stack.split('\n');
|
||||
const head = lines.shift()!;
|
||||
|
||||
Object.defineProperty(this, 'stack', {
|
||||
value: head + '\n' +
|
||||
' from ' + response.url + ' (' + response.status + ' ' + response.statusText + ')\n' +
|
||||
' ' + util.inspect(this.data ? this.data : this.body, {
|
||||
compact: true,
|
||||
}).replace(/\n/g, '\n ') +
|
||||
(lines.length ? '\n' + lines.join('\n') : ''),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user