Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: request render error not display - [INS-4833] #8277

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/insomnia/src/ui/components/request-url-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ export const RequestUrlBar = forwardRef<RequestUrlBarHandle, Props>(({
if (searchParams.has('envVariableMissing') && searchParams.get('undefinedEnvironmentVariables')) {
setShowEnvVariableMissingModal(true);
setUndefinedEnvironmentVariables(searchParams.get('undefinedEnvironmentVariables')!);
} else {
// only for request render error
showAlert({
title: 'Unexpected Request Failure',
message: (
<div>
<p>The request failed due to an unhandled error:</p>
<code className="wide selectable">
<pre>{searchParams.get('error')}</pre>
</code>
</div>
),
});
}

// clean up params
Expand Down
14 changes: 8 additions & 6 deletions packages/insomnia/src/ui/routes/request.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ export const sendAction: ActionFunction = async ({ request, params }) => {
} catch (err) {
console.log('[request] Failed to send request', err);
const e = err.error || err;
const url = new URL(request.url);

// when after-script error, there is no error in response, we need to set error info into response, so that we can show it in response viewer
if (err.response && err.requestMeta && err.response._id) {
Expand All @@ -445,15 +446,16 @@ export const sendAction: ActionFunction = async ({ request, params }) => {
const existingResponse = await models.response.getById(err.response._id);
const response = existingResponse || await models.response.create(err.response, err.maxHistoryResponses);
await models.requestMeta.update(err.requestMeta, { activeResponseId: response._id });
} else {
// if the error is not from response, we need to set it to url param and show it in modal
url.searchParams.set('error', e);
if (e?.extraInfo && e?.extraInfo?.subType === RenderErrorSubType.EnvironmentVariable) {
url.searchParams.set('envVariableMissing', '1');
url.searchParams.set('undefinedEnvironmentVariables', e?.extraInfo?.undefinedEnvironmentVariables);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🇮🇹 🍝

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this logic be cleaned up? Or expressed more simply.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently passing the error message through the URL parameter is not a good way. We could keep the status quo first. I plan to find a new way to replace this


window.main.completeExecutionStep({ requestId });
const url = new URL(request.url);
url.searchParams.set('error', e);
if (e?.extraInfo && e?.extraInfo?.subType === RenderErrorSubType.EnvironmentVariable) {
url.searchParams.set('envVariableMissing', '1');
url.searchParams.set('undefinedEnvironmentVariables', e?.extraInfo?.undefinedEnvironmentVariables);
}
return redirect(`${url.pathname}?${url.searchParams}`);
}
};
Expand Down
Loading