@financial-times/qanda-ui 0.0.1-beta.39 → 0.0.1-beta.40
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.
|
@@ -37,9 +37,7 @@ class HumanReadableError {
|
|
|
37
37
|
this._humanReadableError = errorMessages.connectionError;
|
|
38
38
|
}
|
|
39
39
|
else if (typeof error.status === 'number' && error.status >= 500) {
|
|
40
|
-
|
|
41
|
-
this._humanReadableError =
|
|
42
|
-
errorMessages[typedError.data?.error?.errorCode] || errorMessages.serverError;
|
|
40
|
+
this._humanReadableError = errorMessages.serverError;
|
|
43
41
|
}
|
|
44
42
|
else if (typeof error.status === 'number' && error.status === 400) {
|
|
45
43
|
// Assuming as an error code otherwise will throw an error and we will fallback to generic error
|
|
@@ -52,6 +50,9 @@ class HumanReadableError {
|
|
|
52
50
|
if (error.name === 'AbortError') {
|
|
53
51
|
this._humanReadableError = errorMessages.timeoutError;
|
|
54
52
|
}
|
|
53
|
+
if (error.name === 'maintenanceMode') {
|
|
54
|
+
this._humanReadableError = errorMessages.maintenanceMode;
|
|
55
|
+
}
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
catch (err) {
|
|
@@ -11,6 +11,12 @@ exports.updateTypes = {
|
|
|
11
11
|
QA_NEW_REPLY: 'updatedComments',
|
|
12
12
|
QA_UPDATE: 'updatedQA',
|
|
13
13
|
};
|
|
14
|
+
class MaintenanceModeError extends Error {
|
|
15
|
+
constructor() {
|
|
16
|
+
super('maintenanceMode');
|
|
17
|
+
this.name = 'maintenanceMode';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
14
20
|
exports.eventSource = null;
|
|
15
21
|
exports.nextCommentsApi = (0, react_1.createApi)({
|
|
16
22
|
reducerPath: 'nextCommentsApi',
|
|
@@ -25,6 +31,9 @@ exports.nextCommentsApi = (0, react_1.createApi)({
|
|
|
25
31
|
// The usage of status is to create different caches (RTK and Fastly) for different statuses
|
|
26
32
|
`${commentsAPIUrl}/story/${storyId}/stream?status=${status}${useStaging ? '&staging=1' : ''}`,
|
|
27
33
|
transformResponse: (response) => {
|
|
34
|
+
if (response.type === 'MAINTENANCE_MODE') {
|
|
35
|
+
throw new MaintenanceModeError();
|
|
36
|
+
}
|
|
28
37
|
return {
|
|
29
38
|
qandas: response?.children || [],
|
|
30
39
|
type: response.type,
|
|
@@ -149,6 +158,9 @@ exports.nextCommentsApi = (0, react_1.createApi)({
|
|
|
149
158
|
},
|
|
150
159
|
}),
|
|
151
160
|
transformResponse: (response, meta, arg) => {
|
|
161
|
+
if (response.type === 'MAINTENANCE_MODE') {
|
|
162
|
+
throw new MaintenanceModeError();
|
|
163
|
+
}
|
|
152
164
|
const allowedRoles = ['ADMIN', 'MODERATOR'];
|
|
153
165
|
const { isExpert, isStaffExpert, role } = response;
|
|
154
166
|
const expertView = isExpert || isStaffExpert || !!(role && allowedRoles.includes(role));
|
|
@@ -35,9 +35,7 @@ export default class HumanReadableError {
|
|
|
35
35
|
this._humanReadableError = errorMessages.connectionError;
|
|
36
36
|
}
|
|
37
37
|
else if (typeof error.status === 'number' && error.status >= 500) {
|
|
38
|
-
|
|
39
|
-
this._humanReadableError =
|
|
40
|
-
errorMessages[typedError.data?.error?.errorCode] || errorMessages.serverError;
|
|
38
|
+
this._humanReadableError = errorMessages.serverError;
|
|
41
39
|
}
|
|
42
40
|
else if (typeof error.status === 'number' && error.status === 400) {
|
|
43
41
|
// Assuming as an error code otherwise will throw an error and we will fallback to generic error
|
|
@@ -50,6 +48,9 @@ export default class HumanReadableError {
|
|
|
50
48
|
if (error.name === 'AbortError') {
|
|
51
49
|
this._humanReadableError = errorMessages.timeoutError;
|
|
52
50
|
}
|
|
51
|
+
if (error.name === 'maintenanceMode') {
|
|
52
|
+
this._humanReadableError = errorMessages.maintenanceMode;
|
|
53
|
+
}
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
catch (err) {
|
|
@@ -8,6 +8,12 @@ export const updateTypes = {
|
|
|
8
8
|
QA_NEW_REPLY: 'updatedComments',
|
|
9
9
|
QA_UPDATE: 'updatedQA',
|
|
10
10
|
};
|
|
11
|
+
class MaintenanceModeError extends Error {
|
|
12
|
+
constructor() {
|
|
13
|
+
super('maintenanceMode');
|
|
14
|
+
this.name = 'maintenanceMode';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
11
17
|
export let eventSource = null;
|
|
12
18
|
export const nextCommentsApi = createApi({
|
|
13
19
|
reducerPath: 'nextCommentsApi',
|
|
@@ -22,6 +28,9 @@ export const nextCommentsApi = createApi({
|
|
|
22
28
|
// The usage of status is to create different caches (RTK and Fastly) for different statuses
|
|
23
29
|
`${commentsAPIUrl}/story/${storyId}/stream?status=${status}${useStaging ? '&staging=1' : ''}`,
|
|
24
30
|
transformResponse: (response) => {
|
|
31
|
+
if (response.type === 'MAINTENANCE_MODE') {
|
|
32
|
+
throw new MaintenanceModeError();
|
|
33
|
+
}
|
|
25
34
|
return {
|
|
26
35
|
qandas: response?.children || [],
|
|
27
36
|
type: response.type,
|
|
@@ -146,6 +155,9 @@ export const nextCommentsApi = createApi({
|
|
|
146
155
|
},
|
|
147
156
|
}),
|
|
148
157
|
transformResponse: (response, meta, arg) => {
|
|
158
|
+
if (response.type === 'MAINTENANCE_MODE') {
|
|
159
|
+
throw new MaintenanceModeError();
|
|
160
|
+
}
|
|
149
161
|
const allowedRoles = ['ADMIN', 'MODERATOR'];
|
|
150
162
|
const { isExpert, isStaffExpert, role } = response;
|
|
151
163
|
const expertView = isExpert || isStaffExpert || !!(role && allowedRoles.includes(role));
|