showing error response in response tab instead of alert message

This commit is contained in:
therealrinku 2023-10-09 12:33:10 +05:45
parent 159dd90b03
commit fdca86ffd2
3 changed files with 19 additions and 13 deletions

View File

@ -3,7 +3,7 @@ import styled from 'styled-components';
const StyledWrapper = styled.div` const StyledWrapper = styled.div`
position: absolute; position: absolute;
z-index: 1; z-index: 1;
height: 100vh; height: 75vh;
background-color: ${(props) => props.theme.requestTabPanel.responseOverlayBg}; background-color: ${(props) => props.theme.requestTabPanel.responseOverlayBg};
div.overlay { div.overlay {

View File

@ -116,8 +116,13 @@ const ResponsePane = ({ rightPaneWidth, item, collection }) => {
) : null} ) : null}
</div> </div>
<section className={`flex flex-grow ${focusedTab.responsePaneTab === 'response' ? '' : 'mt-4'}`}> <section className={`flex flex-grow ${focusedTab.responsePaneTab === 'response' ? '' : 'mt-4'}`}>
{isLoading ? <Overlay item={item} collection={collection} /> : null} {isLoading && <Overlay item={item} collection={collection} />}
{getTabPanel(focusedTab.responsePaneTab)}
{response.isError ? (
<span className="mt-5 px-5 text-red-500">{response.error}</span>
) : (
getTabPanel(focusedTab.responsePaneTab)
)}
</section> </section>
</StyledWrapper> </StyledWrapper>
); );

View File

@ -117,22 +117,23 @@ export const sendRequest = (item, collectionUid) => (dispatch, getState) => {
}) })
.then(resolve) .then(resolve)
.catch((err) => { .catch((err) => {
const errorMessage = err.message ?? 'Something went wrong';
const errorResponse = {
status: 'Error',
isError: true,
error: errorMessage,
size: '0',
duration: '0'
};
dispatch( dispatch(
responseReceived({ responseReceived({
itemUid: item.uid, itemUid: item.uid,
collectionUid: collectionUid, collectionUid: collectionUid,
response: null response: errorResponse
}) })
); );
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!');
}); });
}); });
}; };