Skip to content

Commit 5c2388a

Browse files
authored
Merge pull request #30 from qoretechnologies/bugfix/fix-401-redirection
Add VSCode settings and update reqore dependency to 0.49.1; enhance error handling in fetch utility
2 parents 86a37b1 + 6a51ea3 commit 5c2388a

File tree

7 files changed

+50
-23
lines changed

7 files changed

+50
-23
lines changed

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"deepscan.enable": true
3+
}

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@qoretechnologies/reqraft",
3-
"version": "0.6.10",
3+
"version": "0.6.11",
44
"description": "ReQraft is a collection of React components and hooks that are used across Qore Technologies' products made using the ReQore component library from Qore.",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
@@ -53,7 +53,7 @@
5353
"@babel/preset-typescript": "^7.12.7",
5454
"@chromatic-com/storybook": "^2.0.2",
5555
"@netsells/storybook-mockdate": "^0.3.3",
56-
"@qoretechnologies/reqore": "^0.48.18",
56+
"@qoretechnologies/reqore": "^0.49.1",
5757
"@storybook/addon-actions": "^8.3.5",
5858
"@storybook/addon-essentials": "^8.3.5",
5959
"@storybook/addon-interactions": "^8.3.5",

src/components/log/Log.stories.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ export const WithAutoScrollAndManualScroll: Story = {
227227
},
228228
play: async (args) => {
229229
await WithAutoScroll.play(args);
230+
await sleep(3000);
230231
await fireEvent.scroll(document.querySelector('.reqore-panel-content'), {
231232
target: { scrollTop: 100 },
232233
});

src/hooks/useWebSocket/useWebsocket.stories.tsx

+21-12
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ const CompWithHook = (args: IUseReqraftWebSocketOptions) => {
2626
{ label: 'Send', icon: 'MessageLine', onClick: () => send('This is a test message') },
2727
]}
2828
>
29-
{args.includeLogMessagesInState || args.useState ?
29+
{args.includeLogMessagesInState || args.useState ? (
3030
<ReqoreControlGroup vertical>
3131
{messages.map(({ message }, index) => (
3232
<ReqoreP key={index}>{message}</ReqoreP>
3333
))}
3434
</ReqoreControlGroup>
35-
: null}
35+
) : null}
3636
</ReqorePanel>
3737
);
3838
};
@@ -94,6 +94,9 @@ const meta = {
9494
},
9595
parameters: {
9696
chromatic: { disable: true },
97+
jest: {
98+
timeout: 60000,
99+
},
97100
},
98101
render: (args) => {
99102
return <CompWithHook {...args} />;
@@ -155,6 +158,11 @@ export const ReconnectFails: Story = {
155158
openOnMount: true,
156159
reconnectInterval: 500,
157160
},
161+
parameters: {
162+
jest: {
163+
timeout: 60000,
164+
},
165+
},
158166
play: async ({ args, ...rest }) => {
159167
await OpenOnMount.play({ args, ...rest });
160168
await testsClickButton({ label: 'Kill' });
@@ -240,13 +248,13 @@ const ConnectionOne = ({ onPanelClose, ...args }: IConnectionProps) => {
240248
{ label: 'Send', icon: 'MessageLine', onClick: () => send('This is a test message') },
241249
]}
242250
>
243-
{args.includeLogMessagesInState || args.useState ?
251+
{args.includeLogMessagesInState || args.useState ? (
244252
<ReqoreControlGroup vertical>
245253
{messages.map(({ message }, index) => (
246254
<ReqoreP key={index}>{message}</ReqoreP>
247255
))}
248256
</ReqoreControlGroup>
249-
: null}
257+
) : null}
250258
</ReqorePanel>
251259
);
252260
};
@@ -280,13 +288,13 @@ const ConnectionTwo = ({ onPanelClose, ...args }: IConnectionProps) => {
280288
{ label: 'Send', icon: 'MessageLine', onClick: () => send('This is a test message') },
281289
]}
282290
>
283-
{args.includeLogMessagesInState || args.useState ?
291+
{args.includeLogMessagesInState || args.useState ? (
284292
<ReqoreControlGroup vertical>
285293
{messages.map(({ message }, index) => (
286294
<ReqoreP key={index}>{message}</ReqoreP>
287295
))}
288296
</ReqoreControlGroup>
289-
: null}
297+
) : null}
290298
</ReqorePanel>
291299
);
292300
};
@@ -309,10 +317,11 @@ const ConnectionThree = ({ onPanelClose, ...args }: IConnectionProps) => {
309317
minimal
310318
fluid
311319
intent={
312-
status === 'CLOSED' ? 'danger'
313-
: status === 'CONNECTING' ?
314-
'pending'
315-
: ('success' as TReqoreIntent)
320+
status === 'CLOSED'
321+
? 'danger'
322+
: status === 'CONNECTING'
323+
? 'pending'
324+
: ('success' as TReqoreIntent)
316325
}
317326
size='small'
318327
closeButtonProps={{
@@ -328,13 +337,13 @@ const ConnectionThree = ({ onPanelClose, ...args }: IConnectionProps) => {
328337
{ label: 'Send', icon: 'MessageLine', onClick: () => send('This is a test message') },
329338
]}
330339
>
331-
{args.includeLogMessagesInState || args.useState ?
340+
{args.includeLogMessagesInState || args.useState ? (
332341
<ReqoreControlGroup vertical>
333342
{messages.map(({ message }, index) => (
334343
<ReqoreP key={index}>{message}</ReqoreP>
335344
))}
336345
</ReqoreControlGroup>
337-
: null}
346+
) : null}
338347
</ReqorePanel>
339348
);
340349
};

src/utils/fetch.ts

+14-4
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,25 @@ export async function query<T>({
8585
queryFn: async () => {
8686
const response = await doFetchData(url, method, body);
8787

88+
if (
89+
response.status === 401 &&
90+
process.env.NODE_ENV !== 'test' &&
91+
process.env.NODE_ENV !== 'storybook'
92+
) {
93+
window.location.href = fetchConfig.unauthorizedRedirect(window.location.pathname);
94+
}
95+
8896
const clone = response.clone();
89-
const json = await clone.json();
97+
let data: any;
9098

91-
if (response.status === 401) {
92-
window.location.href = fetchConfig.unauthorizedRedirect(window.location.pathname);
99+
try {
100+
data = await clone.json();
101+
} catch (error) {
102+
data = {};
93103
}
94104

95105
return {
96-
data: json,
106+
data,
97107
ok: response.ok,
98108
status: response.status,
99109
statusText: response.statusText,

src/utils/websocket.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,11 @@ export class ReqraftWebSocket {
175175
public async checkServerStatus() {
176176
const check = await query({ url: '/system/pid', cache: false });
177177

178-
if (check.code === 401) {
178+
if (
179+
check.code === 401 &&
180+
process.env.NODE_ENV !== 'test' &&
181+
process.env.NODE_ENV !== 'storybook'
182+
) {
179183
// Qorus is back up again but we need to re-authenticate
180184
// Get the current pathname and redirect to the login page
181185
window.location.href = fetchConfig.unauthorizedRedirect(window.location.pathname);

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -1682,10 +1682,10 @@
16821682
resolved "https://registry.npmjs.org/@popperjs/core/-/core-2.11.8.tgz"
16831683
integrity sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==
16841684

1685-
"@qoretechnologies/reqore@^0.48.18":
1686-
version "0.48.18"
1687-
resolved "https://registry.yarnpkg.com/@qoretechnologies/reqore/-/reqore-0.48.18.tgz#b6a438dafa5e60912790da6fe6a9c07e5a710d9c"
1688-
integrity sha512-8mGVuUfWJ/a7sssfRSFMd5wcDUPAAPinAtBDXyDVZehAu8GXfyQzNbacYWptp5nVEP53CkIEDTwxHKL4rI/FVg==
1685+
"@qoretechnologies/reqore@^0.49.1":
1686+
version "0.49.1"
1687+
resolved "https://registry.yarnpkg.com/@qoretechnologies/reqore/-/reqore-0.49.1.tgz#db1f3f37e39a0aff8ad963883ea4867e322ae8ec"
1688+
integrity sha512-JV3EnPj6AAIKEAC01YEhfJKJr7IEnjaEnD0HJeCEAwhFTlFG6hWMj2VpjMzXTEi8AJKVuAr4qdQp9Y/JeKLq7A==
16891689
dependencies:
16901690
"@internationalized/date" "^3.5.3"
16911691
"@popperjs/core" "^2.11.6"

0 commit comments

Comments
 (0)