Socket
Socket
Sign inDemoInstall

@vitrical/utils

Package Overview
Dependencies
Maintainers
1
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vitrical/utils - npm Package Compare versions

Comparing version 1.5.2 to 1.5.3

3

api.d.ts

@@ -1,2 +0,1 @@

import { AxiosError } from 'axios';
export declare class ApiError extends Error {

@@ -11,3 +10,3 @@ url: string;

}
export declare const handleApiError: (url: string, newStack: string, err: AxiosError) => ApiError | Error | unknown;
export declare const handleApiError: (url: string, newStack: string, err: unknown) => ApiError | Error | unknown;
export type CustomRequestResponse<R = any> = {

@@ -14,0 +13,0 @@ status: number;

@@ -18,12 +18,22 @@ "use strict";

const handleApiError = (url, newStack, err) => {
if (!err?.response) {
if (typeof err === 'string') {
const newError = new Error(err);
newError.stack = newStack;
newError.message = err;
return newError;
}
if (typeof err === 'string') {
const newError = new Error(err);
newError.stack = newStack;
return newError;
}
if (typeof err !== 'object' || !err) {
return err;
}
if (err?.response?.status && typeof err?.response?.status === 'number' && !!err?.response?.data) {
if (!('response' in err)) {
return err;
}
if (typeof err.response === 'string') {
const newError = new Error(err.response);
newError.stack = newStack;
return newError;
}
if (typeof err.response !== 'object' || !err.response) {
return err;
}
if ('status' in err.response && typeof err?.response?.status === 'number') {
if (typeof err === 'object' &&

@@ -38,3 +48,3 @@ !!err &&

}
const body = err.response.data;
const body = 'data' in err.response ? err.response.data : err.response;
let requestMsg = undefined;

@@ -45,15 +55,21 @@ if (typeof body === 'string') {

else if (typeof body === 'object' && !!body) {
if ('msg' in body && typeof body?.msg === 'string') {
if ('msg' in body && typeof body.msg === 'string') {
requestMsg = body.msg;
}
else if ('error' in body && typeof body?.error === 'string') {
else if ('error' in body && typeof body.error === 'string') {
requestMsg = body.error;
}
else if ('message' in body && typeof body?.message === 'string') {
else if ('message' in body && typeof body.message === 'string') {
requestMsg = body.message;
}
else if ('text' in body && typeof body?.text === 'string') {
else if ('text' in body && typeof body.text === 'string') {
requestMsg = body.text;
}
else {
requestMsg = JSON.stringify(body);
}
}
else {
requestMsg = JSON.stringify(body);
}
const message = requestMsg

@@ -63,4 +79,9 @@ ? `Request failed with status code ${err.response.status} ( ${requestMsg} )`

const apiError = new ApiError(message);
apiError.body = err.response.data;
apiError.headers = err.response.headers;
apiError.body = 'data' in err.response ? err.response.data : err.response;
apiError.headers =
'headers' in err.response &&
typeof err.response.headers === 'object' &&
!!err.response.headers
? err.response.headers
: {};
apiError.status = err.response.status;

@@ -73,3 +94,3 @@ apiError.stack = newStack;

else {
if ('message' in err) {
if ('message' in err && typeof err.message === 'string') {
const newError = new Error(err.message);

@@ -76,0 +97,0 @@ newError.stack = newStack;

{
"name": "@vitrical/utils",
"version": "1.5.2",
"version": "1.5.3",
"description": "Collection of useful functions and typings",

@@ -5,0 +5,0 @@ "main": "index.js",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc