Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/errors/apps-sdk-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export enum ERROR_CODE {
FORBIDDEN = 'forbidden',
NOT_FOUND = 'not found',
BAD_REQUEST = 'bad request',
INTERNAL_SERVER = 'internal server error'
INTERNAL_SERVER = 'internal server error',
TOO_MANY_REQUESTS = 'too many requests'
}

export class BaseError extends Error {
Expand Down Expand Up @@ -44,3 +45,9 @@ export class ForbiddenError extends BaseError {
super(ERROR_CODE.FORBIDDEN, message, StatusCodes.FORBIDDEN);
}
}

export class TooManyRequestsError extends BaseError {
constructor(public message: string) {
super(ERROR_CODE.TOO_MANY_REQUESTS, message, StatusCodes.TOO_MANY_REQUESTS);
}
}
2 changes: 1 addition & 1 deletion lib/minimal-package.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default { name: '@mondaycom/apps-sdk', version: '3.1.0' };
export default { name: '@mondaycom/apps-sdk', version: '3.2.0-beta.6' };
6 changes: 5 additions & 1 deletion lib/secure-storage/secure-storage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BadRequestError, InternalServerError } from 'errors/apps-sdk-error';
import { BadRequestError, BaseError, ERROR_CODE, InternalServerError } from 'errors/apps-sdk-error';
import { getGcpConnectionData, getGcpIdentityToken } from 'lib/gcp/gcp';
import { MONDAY_CODE_RESERVED_PRIMITIVES_KEY } from 'lib/secure-storage/secure-storage.consts';
import { RequestOptions } from 'types/fetch';
Expand Down Expand Up @@ -45,6 +45,10 @@ const secureStorageFetch = async <T>(path: string, connectionData: ConnectionDat
try {
result = await fetchWrapper<VaultBaseResponse>(path, fetchObj);
} catch (error: unknown) {
if ((error as BaseError).errorCode === ERROR_CODE.TOO_MANY_REQUESTS) {
logger.warn('[secureStorageFetch] Rate limit exceeded while communicating with secure storage', { error: error as Error });
throw error;
}
logger.error('[secureStorageFetch] Unexpected error occurred while communicating with secure storage', { error: error as Error });
throw new InternalServerError('An issue occurred while accessing secure storage');
}
Expand Down
5 changes: 4 additions & 1 deletion lib/utils/fetch-wrapper.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { StatusCodes } from 'http-status-codes';
import fetch, { RequestInit, Response } from 'node-fetch';

import { ForbiddenError } from 'errors/apps-sdk-error';
import { ForbiddenError, TooManyRequestsError } from 'errors/apps-sdk-error';

const handleFetchErrors = (response: Response): void => {
if (response.status == StatusCodes.FORBIDDEN) {
throw new ForbiddenError('Forbidden action');
}
if (response.status == StatusCodes.TOO_MANY_REQUESTS) {
throw new TooManyRequestsError('request limit exceeded');
}
};

export async function fetchWrapper<TResponse>(
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mondaycom/apps-sdk",
"version": "3.1.0",
"version": "3.2.0-beta.6",
"description": "monday apps SDK for NodeJS",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
Expand Down
Loading