Skip to content

Commit 6c2c201

Browse files
committed
chore: update version to 1.9.5-beta-6 in package.json and package-lock.json; add shouldParseServerErrorForUnauthorizedUser option to CoreAPI
1 parent b29c8ea commit 6c2c201

File tree

5 files changed

+15
-4
lines changed

5 files changed

+15
-4
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "1.9.5-beta-5",
3+
"version": "1.9.5-beta-6",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Common/API/CoreAPI.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class CoreAPI {
2525
signal,
2626
preventAutoLogout = false,
2727
preventLicenseRedirect = false,
28+
shouldParseServerErrorForUnauthorizedUser = false,
2829
isMultipartRequest,
2930
}: FetchAPIParamsType<K>): Promise<ResponseType> => {
3031
const options: RequestInit = {
@@ -60,6 +61,11 @@ class CoreAPI {
6061
const contentType = response.headers.get('Content-Type')
6162
if (response.status === API_STATUS_CODES.UNAUTHORIZED) {
6263
if (preventAutoLogout) {
64+
if (shouldParseServerErrorForUnauthorizedUser) {
65+
await handleServerError(contentType, response)
66+
// Won't reach here as handleServerError will throw an error
67+
return null
68+
}
6369
throw new ServerErrors({
6470
code: API_STATUS_CODES.UNAUTHORIZED,
6571
errors: [
@@ -161,6 +167,7 @@ class CoreAPI {
161167
signal,
162168
preventAutoLogout: options?.preventAutoLogout || false,
163169
preventLicenseRedirect: options?.preventLicenseRedirect || false,
170+
shouldParseServerErrorForUnauthorizedUser: options?.shouldParseServerErrorForUnauthorizedUser,
164171
isMultipartRequest,
165172
}),
166173
timeoutPromise,

src/Common/API/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ export interface FetchInTimeParamsType<Data = object> {
2323

2424
export interface FetchAPIParamsType<Data = object>
2525
extends Omit<FetchInTimeParamsType<Data>, 'options'>,
26-
Pick<APIOptions, 'preventAutoLogout' | 'preventLicenseRedirect'> {
26+
Pick<APIOptions, 'preventAutoLogout' | 'preventLicenseRedirect' | 'shouldParseServerErrorForUnauthorizedUser'> {
2727
signal: AbortSignal
2828
}

src/Common/Types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ export interface APIOptions {
7373
* @default false
7474
*/
7575
preventLicenseRedirect?: boolean
76+
/**
77+
* @default false
78+
*/
79+
shouldParseServerErrorForUnauthorizedUser?: boolean
7680
}
7781

7882
export interface OptionType<T = string, K = string> {

0 commit comments

Comments
 (0)