Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@based/errors

Package Overview
Dependencies
Maintainers
7
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@based/errors - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

7

dist/src/index.d.ts

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

import { BasedRoute } from '@based/functions';
import { BasedRoute } from "@based/functions";
export declare enum BasedErrorCode {

@@ -59,2 +59,3 @@ incorrectFieldType = 1000,

requestId?: number;
streamRequestId?: number;
route: BasedRoute;

@@ -82,3 +83,6 @@ };

} | {
streamRequestId: number;
route: BasedRoute;
} | {
route: BasedRoute;
};

@@ -160,2 +164,3 @@ type BasedFunctionError = FunctionErrorProps | ObservableFunctionErrorProps | ChannelFunctionErrorProps;

channelId?: number;
streamRequestId?: number;
};

@@ -162,0 +167,0 @@ type ErrorType = {

196

dist/src/index.js

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

import { isAnyBasedRoute } from '@based/functions';
import { isAnyBasedRoute } from "@based/functions";
export var BasedErrorCode;

@@ -56,5 +56,5 @@ (function (BasedErrorCode) {

BasedErrorCode[BasedErrorCode["CannotRemoveLastProperty"] = 2006] = "CannotRemoveLastProperty";
})(BasedErrorCode || (BasedErrorCode = {}));
})(BasedErrorCode = BasedErrorCode || (BasedErrorCode = {}));
const addName = (payload) => {
return payload.name ? `[${payload.name}] ` : '';
return payload.name ? `[${payload.name}] ` : "";
};

@@ -64,69 +64,69 @@ export const errorTypeHandlers = {

[BasedErrorCode.incorrectFieldType]: {
message: (payload) => `[${payload.path.join('.')}] Incorrect field type.`
message: (payload) => `[${payload.path.join(".")}] Incorrect field type.`,
},
[BasedErrorCode.incorrectNodeType]: {
message: (payload) => `[${payload.path.join('.')}] Incorrect node type.`
message: (payload) => `[${payload.path.join(".")}] Incorrect node type.`,
},
[BasedErrorCode.exceedsMaximum]: {
message: (payload) => `[${payload.path.join('.')}] Exceeds maximum property.`
message: (payload) => `[${payload.path.join(".")}] Exceeds maximum property.`,
},
[BasedErrorCode.subceedsMinimum]: {
message: (payload) => `[${payload.path.join('.')}] Subceeds minimum property.`
message: (payload) => `[${payload.path.join(".")}] Subceeds minimum property.`,
},
[BasedErrorCode.fieldDoesNotExist]: {
message: (payload) => `[${payload.path.join('.')}] Field does not exist.`
message: (payload) => `[${payload.path.join(".")}] Field does not exist.`,
},
[BasedErrorCode.incorrectFormat]: {
message: (payload) => `[${payload.path.join('.')}] Incorrect format.`
message: (payload) => `[${payload.path.join(".")}] Incorrect format.`,
},
[BasedErrorCode.referenceIsIncorrectType]: {
message: (payload) => `[${payload.path.join('.')}] Reference is from incorrect type.`
message: (payload) => `[${payload.path.join(".")}] Reference is from incorrect type.`,
},
[BasedErrorCode.valueAndDefault]: {
message: (payload) => `[${payload.path.join('.')}] Value and $default are being used at the same time.`
message: (payload) => `[${payload.path.join(".")}] Value and $default are being used at the same time.`,
},
[BasedErrorCode.defaultNotSupported]: {
message: (payload) => `[${payload.path.join('.')}] $default is not suported.`
message: (payload) => `[${payload.path.join(".")}] $default is not suported.`,
},
[BasedErrorCode.multipleOperationsNotAllowed]: {
message: (payload) => `[${payload.path.join('.')}] Multiple operations are not allowed here.`
message: (payload) => `[${payload.path.join(".")}] Multiple operations are not allowed here.`,
},
[BasedErrorCode.requiredFieldNotDefined]: {
message: (payload) => `[${payload.path.join('.')}] Required field is not defined.`
message: (payload) => `[${payload.path.join(".")}] Required field is not defined.`,
},
[BasedErrorCode.languageNotSupported]: {
message: (payload) => `[${payload.path.join('.')}] Language not supported.`
message: (payload) => `[${payload.path.join(".")}] Language not supported.`,
},
[BasedErrorCode.invalidJSON]: {
message: (payload) => `[${payload.path.join('.')}] Invalid JSON.`
message: (payload) => `[${payload.path.join(".")}] Invalid JSON.`,
},
[BasedErrorCode.noLanguageFound]: {
message: (payload) => `[${payload.path.join('.')}] No language found.`
message: (payload) => `[${payload.path.join(".")}] No language found.`,
},
[BasedErrorCode.cannotDeleteNodeFromModify]: {
message: (payload) => `[${payload.path.join('.')}] Cannot delete node from modify.`
message: (payload) => `[${payload.path.join(".")}] Cannot delete node from modify.`,
},
[BasedErrorCode.nestedModifyObjectNotAllowed]: {
message: (payload) => `[${payload.path.join('.')}] Nested modify object not allowed.`
message: (payload) => `[${payload.path.join(".")}] Nested modify object not allowed.`,
},
[BasedErrorCode.infinityNotSupported]: {
message: (payload) => `[${payload.path.join('.')}] Infinity not supported.`
message: (payload) => `[${payload.path.join(".")}] Infinity not supported.`,
},
[BasedErrorCode.invalidSchemaFormat]: {
message: (payload) => `[${payload.path.join('.')}] Invalid schema format.`
message: (payload) => `[${payload.path.join(".")}] Invalid schema format.`,
},
[BasedErrorCode.invalidProperty]: {
message: (payload) => `[${payload.path.join('.')}] Invalid property.`
message: (payload) => `[${payload.path.join(".")}] Invalid property.`,
},
[BasedErrorCode.FunctionError]: {
statusCode: 500,
statusMessage: 'Internal Server Error',
statusMessage: "Internal Server Error",
message: (payload) => {
if (typeof payload.err === 'string' || !payload.err.message) {
if (typeof payload.err === "string" || !payload.err.message) {
return `[${payload.route.name}] ${JSON.stringify(payload.err)}`;
}
return (addName(payload.route) +
`${payload.err.name && payload.err.name !== 'Error'
`${payload.err.name && payload.err.name !== "Error"
? `[${payload.err.name}] `
: ''}${payload.err.message || ''}.`);
: ""}${payload.err.message || ""}.`);
},

@@ -136,11 +136,11 @@ },

statusCode: 403,
statusMessage: 'Forbidden',
statusMessage: "Forbidden",
message: (payload) => {
if (typeof payload.err === 'string' || !payload.err.message) {
if (typeof payload.err === "string" || !payload.err.message) {
return `[${payload.route.name}] ${JSON.stringify(payload.err)}`;
}
return (addName(payload.route) +
`${payload.err.name && payload.err.name !== 'Error'
`${payload.err.name && payload.err.name !== "Error"
? `[${payload.err.name}] `
: ''}${payload.err.message || ''}.`);
: ""}${payload.err.message || ""}.`);
},

@@ -150,3 +150,3 @@ },

statusCode: 500,
statusMessage: 'Internal Server Error',
statusMessage: "Internal Server Error",
message: (payload) => addName(payload.route) +

@@ -157,11 +157,11 @@ `No observable cache available${payload.route.name} - ${payload.observableId}.`,

statusCode: 500,
statusMessage: 'Internal Server Error',
statusMessage: "Internal Server Error",
message: (payload) => {
if (typeof payload.err === 'string' || !payload.err.message) {
if (typeof payload.err === "string" || !payload.err.message) {
return `[${payload.route.name} (observable)] ${JSON.stringify(payload.err)}.`;
}
return (addName(payload.route) +
`${payload.err.name && payload.err.name !== 'Error'
`${payload.err.name && payload.err.name !== "Error"
? `[${payload.err.name}] `
: ''}${payload.err.message || ''}.`);
: ""}${payload.err.message || ""}.`);
},

@@ -171,5 +171,5 @@ },

statusCode: 500,
statusMessage: 'Internal Server Error',
statusMessage: "Internal Server Error",
message: () => {
return 'Error in server side observer.';
return "Error in server side observer.";
},

@@ -179,6 +179,6 @@ },

statusCode: 404,
statusMessage: 'Not Found',
statusMessage: "Not Found",
message: (payload) => {
return (addName(payload.route) +
`Function not found${payload.route.path ? ` path '${payload.route.path}'` : ''}.`);
`Function not found${payload.route.path ? ` path '${payload.route.path}'` : ""}.`);
},

@@ -188,5 +188,5 @@ },

statusCode: 400,
statusMessage: 'Incorrect Protocol',
statusMessage: "Incorrect Protocol",
message: (payload) => {
return addName(payload.route) + 'Target function is not observable.';
return addName(payload.route) + "Target function is not observable.";
},

@@ -196,5 +196,5 @@ },

statusCode: 400,
statusMessage: 'Incorrect Protocol',
statusMessage: "Incorrect Protocol",
message: (payload) => {
return addName(payload.route) + 'Target function is observable.';
return addName(payload.route) + "Target function is observable.";
},

@@ -204,5 +204,5 @@ },

statusCode: 400,
statusMessage: 'Incorrect Protocol',
statusMessage: "Incorrect Protocol",
message: (payload) => {
return addName(payload.route) + 'Target function is stream.';
return addName(payload.route) + "Target function is stream.";
},

@@ -212,5 +212,5 @@ },

statusCode: 400,
statusMessage: 'Incorrect Protocol',
statusMessage: "Incorrect Protocol",
message: (payload) => {
return addName(payload.route) + 'Cannot stream to observable function.';
return addName(payload.route) + "Cannot stream to observable function.";
},

@@ -220,5 +220,5 @@ },

statusCode: 400,
statusMessage: 'Incorrect Protocol',
statusMessage: "Incorrect Protocol",
message: (payload) => {
return addName(payload.route) + 'Target function is of wrong type.';
return addName(payload.route) + "Target function is of wrong type.";
},

@@ -228,3 +228,3 @@ },

statusCode: 403,
statusMessage: 'Forbidden',
statusMessage: "Forbidden",
message: (payload) => addName(payload.route) + `Authorize rejected access.`,

@@ -234,81 +234,81 @@ },

statusCode: 400,
statusMessage: 'Bad Request',
message: (payload) => addName(payload.route) + 'Invalid payload.',
statusMessage: "Bad Request",
message: (payload) => addName(payload.route) + "Invalid payload.",
},
[BasedErrorCode.PayloadTooLarge]: {
statusCode: 413,
statusMessage: 'Payload Too Large',
message: (payload) => addName(payload.route) + ' PayloadTooLarge.',
statusMessage: "Payload Too Large",
message: (payload) => addName(payload.route) + " PayloadTooLarge.",
},
[BasedErrorCode.ChunkTooLarge]: {
statusCode: 413,
statusMessage: 'Payload Too Large',
message: (payload) => addName(payload) + 'ChunkTooLarge ' + payload.name + '.',
statusMessage: "Payload Too Large",
message: (payload) => addName(payload) + "ChunkTooLarge " + payload.name + ".",
},
[BasedErrorCode.UnsupportedContentEncoding]: {
statusCode: 400,
statusMessage: 'Incorrect content encoding',
message: (payload) => addName(payload) + 'Incorrect content encoding.',
statusMessage: "Incorrect content encoding",
message: (payload) => addName(payload) + "Incorrect content encoding.",
},
[BasedErrorCode.NoBinaryProtocol]: {
statusCode: 400,
statusMessage: 'Protocol mismatch',
message: () => 'Please upgrade to the latest based client.',
statusMessage: "Protocol mismatch",
message: () => "Please upgrade to the latest based client.",
},
[BasedErrorCode.LengthRequired]: {
statusCode: 411,
statusMessage: 'Length Required',
message: (payload) => addName(payload) + 'Length Required.',
statusMessage: "Length Required",
message: (payload) => addName(payload) + "Length Required.",
},
[BasedErrorCode.MethodNotAllowed]: {
statusCode: 405,
statusMessage: 'Method Not Allowed',
message: (payload) => addName(payload) + 'Method Not Allowed.',
statusMessage: "Method Not Allowed",
message: (payload) => addName(payload) + "Method Not Allowed.",
},
[BasedErrorCode.RateLimit]: {
statusCode: 429,
statusMessage: 'Rate limit',
message: () => 'Rate limit.',
statusMessage: "Rate limit",
message: () => "Rate limit.",
},
[BasedErrorCode.MissingAuthStateProtocolHeader]: {
statusCode: 500,
statusMessage: 'Internal Server Error',
message: () => '',
statusMessage: "Internal Server Error",
message: () => "",
},
[BasedErrorCode.IncorrectAccessKey]: {
statusCode: 429,
statusMessage: 'Rate limit',
message: () => 'Rate limit.',
statusMessage: "Rate limit",
message: () => "Rate limit.",
},
[BasedErrorCode.Block]: {
statusCode: 429,
statusMessage: 'Blocked ip',
message: () => 'Blocked ip.',
statusMessage: "Blocked ip",
message: () => "Blocked ip.",
},
[BasedErrorCode.PrefixAlreadyInUse]: {
message: (payload) => `[${payload.path.join('.')}] Prefix already in use.`
message: (payload) => `[${payload.path.join(".")}] Prefix already in use.`,
},
[BasedErrorCode.CannotChangeFieldInStrictMode]: {
message: (payload) => `[${payload.path.join('.')}] Cannot change field in strict mode.`
message: (payload) => `[${payload.path.join(".")}] Cannot change field in strict mode.`,
},
[BasedErrorCode.CannotRemoveFieldInStrictMode]: {
message: (payload) => `[${payload.path.join('.')}] Cannot remove field in strict mode.`
message: (payload) => `[${payload.path.join(".")}] Cannot remove field in strict mode.`,
},
[BasedErrorCode.CannotMutateWithExistingData]: {
message: (payload) => `[${payload.path.join('.')}] Cannot mutate with existing data.`
message: (payload) => `[${payload.path.join(".")}] Cannot mutate with existing data.`,
},
[BasedErrorCode.CannotDeleteRoot]: {
message: (payload) => `[${payload.path.join('.')}] Cannot delete root.`
message: (payload) => `[${payload.path.join(".")}] Cannot delete root.`,
},
[BasedErrorCode.CannotChangeDefaultField]: {
message: (payload) => `[${payload.path.join('.')}] Cannot change default field.`
message: (payload) => `[${payload.path.join(".")}] Cannot change default field.`,
},
[BasedErrorCode.CannotRemoveLastProperty]: {
message: (payload) => `[${payload.path.join('.')}] Cannot remove last property.`
message: (payload) => `[${payload.path.join(".")}] Cannot remove last property.`,
},
};
export const EMPTY_ROUTE = {
name: 'no-route',
path: '',
type: 'function',
name: "no-route",
path: "",
type: "function",
};

@@ -324,3 +324,3 @@ function isServerError(payload) {

? payload
: 'route' in payload
: "route" in payload
? payload.route

@@ -331,11 +331,13 @@ : EMPTY_ROUTE;

message: type.message(payload),
...(isServerError(payload) ? {
statusCode: type.statusCode,
statusMessage: type.statusMessage,
route: {
name: route.name,
path: route.path,
type: route.type,
},
} : null)
...(isServerError(payload)
? {
statusCode: type.statusCode,
statusMessage: type.statusMessage,
route: {
name: route.name,
path: route.path,
type: route.type,
},
}
: null),
};

@@ -348,6 +350,6 @@ }

export const convertDataToBasedError = (payload, stack) => {
if (!payload || typeof payload !== 'object') {
if (!payload || typeof payload !== "object") {
const err = new BasedError(`Payload: ${payload}`);
// err.code = BasedErrorCode.FunctionError
err.name = 'Invalid returned payload';
err.name = "Invalid returned payload";
return err;

@@ -357,3 +359,3 @@ }

const msg = message
? message[0] === '['
? message[0] === "["
? message

@@ -363,5 +365,5 @@ : `[${BasedErrorCode[code]}] ` + message

? JSON.stringify(payload, null, 2)
: 'Cannot read error msg';
: "Cannot read error msg";
const error = new BasedError(msg);
error.stack = stack ? msg + ' ' + stack : msg;
error.stack = stack ? msg + " " + stack : msg;
error.name = BasedErrorCode[code];

@@ -368,0 +370,0 @@ error.code = code;

{
"name": "@based/errors",
"version": "1.1.0",
"version": "1.2.0",
"license": "MIT",

@@ -5,0 +5,0 @@ "type": "module",

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