Skip to content

Commit

Permalink
fix: request render error not display
Browse files Browse the repository at this point in the history
  • Loading branch information
CurryYangxx committed Jan 13, 2025
1 parent 72c5fec commit 4e85cab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
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);
}
}

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

0 comments on commit 4e85cab

Please sign in to comment.