tycho-components 0.45.14 → 0.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/configs/api/apiHandledError.d.ts +3 -1
- package/dist/configs/api/apiHandledError.js +6 -2
- package/dist/configs/api/createApiClient.d.ts +4 -4
- package/dist/configs/api/createApiClient.js +5 -5
- package/dist/configs/api/index.d.ts +1 -1
- package/dist/configs/api/index.js +1 -1
- package/dist/configs/brand.d.ts +1 -1
- package/dist/configs/brand.js +1 -0
- package/package.json +1 -1
|
@@ -5,11 +5,13 @@ export type ApiErrorHandled = AxiosError & {
|
|
|
5
5
|
authErrorHandled?: boolean;
|
|
6
6
|
};
|
|
7
7
|
export declare function isServerError(status: number | undefined): boolean;
|
|
8
|
+
/** Statuses that createApiClient auto-toasts via dispatchServerApiError (5xx + 422). */
|
|
9
|
+
export declare function isAutoHandledHttpError(status: number | undefined): boolean;
|
|
8
10
|
export declare function isAccessDeniedStatus(status: number | undefined): boolean;
|
|
9
11
|
/** HTTP status from an Axios error or a thrown Response-like object. */
|
|
10
12
|
export declare function getHttpErrorStatus(reason: unknown): number | undefined;
|
|
11
13
|
export declare function markApiErrorHandled(error: AxiosError): void;
|
|
12
|
-
/** True when the API client already surfaced a 5xx error via
|
|
14
|
+
/** True when the API client already surfaced a 5xx/422 error via dispatchServerApiError. */
|
|
13
15
|
export declare function isHandledApiError(reason: unknown): boolean;
|
|
14
16
|
/**
|
|
15
17
|
* Unmarked 401/403 from the API (or a Response with that status).
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export function isServerError(status) {
|
|
2
2
|
return status !== undefined && status >= 500 && status < 600;
|
|
3
3
|
}
|
|
4
|
+
/** Statuses that createApiClient auto-toasts via dispatchServerApiError (5xx + 422). */
|
|
5
|
+
export function isAutoHandledHttpError(status) {
|
|
6
|
+
return isServerError(status) || status === 422;
|
|
7
|
+
}
|
|
4
8
|
export function isAccessDeniedStatus(status) {
|
|
5
9
|
return status === 401 || status === 403;
|
|
6
10
|
}
|
|
@@ -20,7 +24,7 @@ export function getHttpErrorStatus(reason) {
|
|
|
20
24
|
export function markApiErrorHandled(error) {
|
|
21
25
|
error.apiErrorHandled = true;
|
|
22
26
|
}
|
|
23
|
-
/** True when the API client already surfaced a 5xx error via
|
|
27
|
+
/** True when the API client already surfaced a 5xx/422 error via dispatchServerApiError. */
|
|
24
28
|
export function isHandledApiError(reason) {
|
|
25
29
|
if (!reason || typeof reason !== 'object')
|
|
26
30
|
return false;
|
|
@@ -30,7 +34,7 @@ export function isHandledApiError(reason) {
|
|
|
30
34
|
const status = err.response?.status;
|
|
31
35
|
if (!err.config || status === undefined)
|
|
32
36
|
return false;
|
|
33
|
-
return
|
|
37
|
+
return isAutoHandledHttpError(status);
|
|
34
38
|
}
|
|
35
39
|
/**
|
|
36
40
|
* Unmarked 401/403 from the API (or a Response with that status).
|
|
@@ -3,14 +3,14 @@ export type ServerErrorHandling = 'toast' | 'none';
|
|
|
3
3
|
export type CreateApiClientOptions = {
|
|
4
4
|
baseURL: string;
|
|
5
5
|
attachJwt?: boolean;
|
|
6
|
-
/** How to surface 5xx responses. Defaults to 'toast'. */
|
|
6
|
+
/** How to surface 5xx/422 responses. Defaults to 'toast'. */
|
|
7
7
|
serverErrorHandling?: ServerErrorHandling;
|
|
8
8
|
augmentRequest?: (config: InternalAxiosRequestConfig) => InternalAxiosRequestConfig;
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
|
-
* Shared API client: JWT attachment + global 5xx
|
|
12
|
-
* Handled 5xx responses resolve (they do not reach .catch()).
|
|
13
|
-
* 4xx are left to front-end callers unless the app opts in via
|
|
11
|
+
* Shared API client: JWT attachment + global 5xx/422 report toast.
|
|
12
|
+
* Handled 5xx/422 responses resolve (they do not reach .catch()).
|
|
13
|
+
* Other 4xx are left to front-end callers unless the app opts in via
|
|
14
14
|
* applyAuthErrorHandling() in its local api.ts wrapper.
|
|
15
15
|
*/
|
|
16
16
|
export declare function createApiClient(options: CreateApiClientOptions): AxiosInstance;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
-
import {
|
|
2
|
+
import { isAutoHandledHttpError, markApiErrorHandled } from './apiHandledError';
|
|
3
3
|
import CookieStorage from '../CookieStorage';
|
|
4
4
|
import { dispatchServerApiError } from './dispatchApiError';
|
|
5
5
|
const DEFAULT_HEADERS = {
|
|
@@ -19,9 +19,9 @@ function toHandledServerErrorResponse(error) {
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
* Shared API client: JWT attachment + global 5xx
|
|
23
|
-
* Handled 5xx responses resolve (they do not reach .catch()).
|
|
24
|
-
* 4xx are left to front-end callers unless the app opts in via
|
|
22
|
+
* Shared API client: JWT attachment + global 5xx/422 report toast.
|
|
23
|
+
* Handled 5xx/422 responses resolve (they do not reach .catch()).
|
|
24
|
+
* Other 4xx are left to front-end callers unless the app opts in via
|
|
25
25
|
* applyAuthErrorHandling() in its local api.ts wrapper.
|
|
26
26
|
*/
|
|
27
27
|
export function createApiClient(options) {
|
|
@@ -32,7 +32,7 @@ export function createApiClient(options) {
|
|
|
32
32
|
});
|
|
33
33
|
api.interceptors.response.use((response) => response, async (error) => {
|
|
34
34
|
const status = error.response?.status;
|
|
35
|
-
if (
|
|
35
|
+
if (isAutoHandledHttpError(status) && serverErrorHandling === 'toast') {
|
|
36
36
|
dispatchServerApiError({ err: error });
|
|
37
37
|
markApiErrorHandled(error);
|
|
38
38
|
return toHandledServerErrorResponse(error);
|
|
@@ -12,7 +12,7 @@ export { createApiClient } from './createApiClient';
|
|
|
12
12
|
export type { CreateApiClientOptions, ServerErrorHandling } from './createApiClient';
|
|
13
13
|
export { applyAuthErrorHandling } from './applyAuthErrorHandling';
|
|
14
14
|
export type { ApplyAuthErrorHandlingOptions, AuthErrorHandling, } from './applyAuthErrorHandling';
|
|
15
|
-
export { isHandledApiError, isHandledAuthError, isAccessDeniedApiError, getHttpErrorStatus, markApiErrorHandled, markAuthErrorHandled, } from './apiHandledError';
|
|
15
|
+
export { isHandledApiError, isHandledAuthError, isAccessDeniedApiError, isAutoHandledHttpError, isServerError, getHttpErrorStatus, markApiErrorHandled, markAuthErrorHandled, } from './apiHandledError';
|
|
16
16
|
export type { ApiErrorHandled, AuthErrorHandled } from './apiHandledError';
|
|
17
17
|
export { buildClientErrorContext, dispatchApiError, dispatchAccessDeniedError, dispatchClientError, dispatchServerApiError, } from './dispatchApiError';
|
|
18
18
|
export { resolveAccessDeniedMessage } from './resolveAccessDeniedMessage';
|
|
@@ -15,7 +15,7 @@ export const lexiconApiBase = import.meta.env.VITE_APP_LEXICON_API ||
|
|
|
15
15
|
const api = applyAuthErrorHandling(createApiClient({ baseURL: platformApiBase }), { authErrorHandling: 'redirect' });
|
|
16
16
|
export { createApiClient } from './createApiClient';
|
|
17
17
|
export { applyAuthErrorHandling } from './applyAuthErrorHandling';
|
|
18
|
-
export { isHandledApiError, isHandledAuthError, isAccessDeniedApiError, getHttpErrorStatus, markApiErrorHandled, markAuthErrorHandled, } from './apiHandledError';
|
|
18
|
+
export { isHandledApiError, isHandledAuthError, isAccessDeniedApiError, isAutoHandledHttpError, isServerError, getHttpErrorStatus, markApiErrorHandled, markAuthErrorHandled, } from './apiHandledError';
|
|
19
19
|
export { buildClientErrorContext, dispatchApiError, dispatchAccessDeniedError, dispatchClientError, dispatchServerApiError, } from './dispatchApiError';
|
|
20
20
|
export { resolveAccessDeniedMessage } from './resolveAccessDeniedMessage';
|
|
21
21
|
export default api;
|
package/dist/configs/brand.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* (not bundled per app — upload packs on each host / shared nginx).
|
|
5
5
|
*/
|
|
6
6
|
export type BrandId = 'tycho' | 'corpushub';
|
|
7
|
-
export type AppCode = 'admin' | 'auth' | 'cs-analyzer' | 'dictionary' | 'editor' | 'io' | 'lexicon' | 'parser' | 'psd-reindexer' | 'reserved' | 'search' | 'syntrees' | 'viewer';
|
|
7
|
+
export type AppCode = 'admin' | 'annotald' | 'auth' | 'cs-analyzer' | 'dictionary' | 'editor' | 'io' | 'lexicon' | 'parser' | 'psd-reindexer' | 'reserved' | 'search' | 'syntrees' | 'viewer';
|
|
8
8
|
export type BrandConfig = {
|
|
9
9
|
id: BrandId;
|
|
10
10
|
name: string;
|
package/dist/configs/brand.js
CHANGED