Merge pull request #471 from therealrinku/two

showing error response in response tab instead of alert message
This commit is contained in:
Anoop M D 2023-10-13 07:10:18 +05:30 committed by GitHub
commit 6c3dc7bbd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 13 deletions

View File

@ -11,7 +11,7 @@ import StyledWrapper from './StyledWrapper';
import { useState } from 'react';
import { useMemo } from 'react';
const QueryResult = ({ item, collection, data, width, disableRunEventListener, headers }) => {
const QueryResult = ({ item, collection, data, width, disableRunEventListener, headers, error }) => {
const { storedTheme } = useTheme();
const [tab, setTab] = useState('preview');
const dispatch = useDispatch();
@ -119,7 +119,7 @@ const QueryResult = ({ item, collection, data, width, disableRunEventListener, h
<div className="flex justify-end gap-2 text-xs" role="tablist">
{getTabs()}
</div>
{activeResult}
{error ? <span className="text-red-500">{error}</span> : activeResult}
</StyledWrapper>
);
};

View File

@ -42,6 +42,7 @@ const ResponsePane = ({ rightPaneWidth, item, collection }) => {
width={rightPaneWidth}
data={response.data}
headers={response.headers}
error={response.error}
/>
);
}

View File

@ -142,22 +142,28 @@ export const sendRequest = (item, collectionUid) => (dispatch, getState) => {
})
.then(resolve)
.catch((err) => {
dispatch(
responseReceived({
itemUid: item.uid,
collectionUid: collectionUid,
response: null
})
);
if (err && err.message === "Error invoking remote method 'send-http-request': Error: Request cancelled") {
console.log('>> request cancelled');
return;
}
console.log('>> sending request failed');
console.log(err);
toast.error(err ? err.message : 'Something went wrong!');
const errorMessage = err.message ?? 'Something went wrong';
const errorResponse = {
status: 'Error',
isError: true,
error: errorMessage,
size: '0',
duration: '0'
};
dispatch(
responseReceived({
itemUid: item.uid,
collectionUid: collectionUid,
response: errorResponse
})
);
});
});
};