mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-08-22 02:53:38 +00:00
use isAxiosError to improve type detection
This commit is contained in:
parent
fefe2f6db8
commit
38b1e1225c
3 changed files with 17 additions and 25 deletions
|
@ -97,6 +97,7 @@
|
||||||
"ajv": "8.17.1",
|
"ajv": "8.17.1",
|
||||||
"archiver": "7.0.1",
|
"archiver": "7.0.1",
|
||||||
"argon2": "^0.40.1",
|
"argon2": "^0.40.1",
|
||||||
|
"axios": "1.7.4",
|
||||||
"async-mutex": "0.5.0",
|
"async-mutex": "0.5.0",
|
||||||
"bcryptjs": "2.4.3",
|
"bcryptjs": "2.4.3",
|
||||||
"blurhash": "2.0.5",
|
"blurhash": "2.0.5",
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { isAxiosError } from 'axios';
|
||||||
import type Logger from '@/logger.js';
|
import type Logger from '@/logger.js';
|
||||||
import { LoggerService } from '@/core/LoggerService.js';
|
import { LoggerService } from '@/core/LoggerService.js';
|
||||||
import { ApiError } from '@/server/api/error.js';
|
import { ApiError } from '@/server/api/error.js';
|
||||||
|
@ -59,14 +60,14 @@ export function getErrorException(error: unknown): Error | null {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AxiosErrors need special decoding
|
// AxiosErrors need special decoding
|
||||||
if (error.name === 'AxiosError') {
|
if (isAxiosError(error)) {
|
||||||
// Axios errors with a response are from the remote
|
// Axios errors with a response are from the remote
|
||||||
if ('response' in error && error.response && typeof (error.response) === 'object') {
|
if (error.response) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is the inner exception, basically
|
// This is the inner exception, basically
|
||||||
if ('cause' in error && error.cause instanceof Error) {
|
if (error.cause && !isAxiosError(error.cause)) {
|
||||||
return error.cause;
|
return error.cause;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,9 +132,9 @@ export function getErrorData(error: unknown): MastodonError {
|
||||||
}
|
}
|
||||||
|
|
||||||
function unpackAxiosError(error: unknown): unknown {
|
function unpackAxiosError(error: unknown): unknown {
|
||||||
if (error && typeof(error) === 'object') {
|
if (isAxiosError(error)) {
|
||||||
if ('response' in error && error.response && typeof (error.response) === 'object') {
|
if (error.response) {
|
||||||
if ('data' in error.response && error.response.data && typeof (error.response.data) === 'object') {
|
if (error.response.data) {
|
||||||
if ('error' in error.response.data && error.response.data.error && typeof(error.response.data.error) === 'object') {
|
if ('error' in error.response.data && error.response.data.error && typeof(error.response.data.error) === 'object') {
|
||||||
return error.response.data.error;
|
return error.response.data.error;
|
||||||
}
|
}
|
||||||
|
@ -145,14 +146,12 @@ function unpackAxiosError(error: unknown): unknown {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error instanceof Error && error.name === 'AxiosError') {
|
if (error.cause && !isAxiosError(error.cause)) {
|
||||||
if ('cause' in error) {
|
return error.cause;
|
||||||
return error.cause;
|
|
||||||
}
|
|
||||||
|
|
||||||
// No data - this is a fallback to avoid leaking request/response details in the error
|
|
||||||
return String(error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// No data - this is a fallback to avoid leaking request/response details in the error
|
||||||
|
return String(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
|
|
16
pnpm-lock.yaml
generated
16
pnpm-lock.yaml
generated
|
@ -182,6 +182,9 @@ importers:
|
||||||
async-mutex:
|
async-mutex:
|
||||||
specifier: 0.5.0
|
specifier: 0.5.0
|
||||||
version: 0.5.0
|
version: 0.5.0
|
||||||
|
axios:
|
||||||
|
specifier: 1.7.4
|
||||||
|
version: 1.7.4
|
||||||
bcryptjs:
|
bcryptjs:
|
||||||
specifier: 2.4.3
|
specifier: 2.4.3
|
||||||
version: 2.4.3
|
version: 2.4.3
|
||||||
|
@ -6417,15 +6420,6 @@ packages:
|
||||||
resolution: {integrity: sha512-Be3narBNt2s6bsaqP6Jzq91heDgOEaDCJAXcE3qcma/EJBSy5FB4cvO31XBInuAuKBx8Kptf8dkhjK0IOru39Q==}
|
resolution: {integrity: sha512-Be3narBNt2s6bsaqP6Jzq91heDgOEaDCJAXcE3qcma/EJBSy5FB4cvO31XBInuAuKBx8Kptf8dkhjK0IOru39Q==}
|
||||||
engines: {node: '>=18'}
|
engines: {node: '>=18'}
|
||||||
|
|
||||||
follow-redirects@1.15.2:
|
|
||||||
resolution: {integrity: sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==}
|
|
||||||
engines: {node: '>=4.0'}
|
|
||||||
peerDependencies:
|
|
||||||
debug: '*'
|
|
||||||
peerDependenciesMeta:
|
|
||||||
debug:
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
follow-redirects@1.15.9:
|
follow-redirects@1.15.9:
|
||||||
resolution: {integrity: sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==}
|
resolution: {integrity: sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==}
|
||||||
engines: {node: '>=4.0'}
|
engines: {node: '>=4.0'}
|
||||||
|
@ -15329,7 +15323,7 @@ snapshots:
|
||||||
|
|
||||||
axios@0.24.0:
|
axios@0.24.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
follow-redirects: 1.15.2
|
follow-redirects: 1.15.9(debug@4.4.0)
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- debug
|
- debug
|
||||||
|
|
||||||
|
@ -17251,8 +17245,6 @@ snapshots:
|
||||||
async: 0.2.10
|
async: 0.2.10
|
||||||
which: 1.3.1
|
which: 1.3.1
|
||||||
|
|
||||||
follow-redirects@1.15.2: {}
|
|
||||||
|
|
||||||
follow-redirects@1.15.9(debug@4.4.0):
|
follow-redirects@1.15.9(debug@4.4.0):
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
debug: 4.4.0(supports-color@8.1.1)
|
debug: 4.4.0(supports-color@8.1.1)
|
||||||
|
|
Loading…
Add table
Reference in a new issue