Catch URL error when URL = "{{HOST}}"

This commit is contained in:
Gregory Schier
2024-02-11 09:04:27 -08:00
parent 13bfc1c3bd
commit 5892774082
2 changed files with 47 additions and 40 deletions

View File

@@ -80,10 +80,16 @@ pub async fn send_http_request(
)); ));
} }
// .use_rustls_tls() // TODO: Make this configurable (maybe)
let client = client_builder.build().expect("Failed to build client"); let client = client_builder.build().expect("Failed to build client");
let url = match Url::from_str(url_string.as_str()) { let uri = match http::Uri::from_str(url_string.as_str()) {
Ok(u) => u,
Err(e) => {
return response_err(response, e.to_string(), window).await;
}
};
// Yes, we're parsing both URI and URL because they could return different errors
let url = match Url::from_str(uri.to_string().as_str()) {
Ok(u) => u, Ok(u) => u,
Err(e) => { Err(e) => {
return response_err(response, e.to_string(), window).await; return response_err(response, e.to_string(), window).await;
@@ -92,7 +98,7 @@ pub async fn send_http_request(
let m = Method::from_bytes(request.method.to_uppercase().as_bytes()) let m = Method::from_bytes(request.method.to_uppercase().as_bytes())
.expect("Failed to create method"); .expect("Failed to create method");
let mut request_builder = client.request(m, url.clone()); let mut request_builder = client.request(m, url);
let mut headers = HeaderMap::new(); let mut headers = HeaderMap::new();
headers.insert(USER_AGENT, HeaderValue::from_static("yaak")); headers.insert(USER_AGENT, HeaderValue::from_static("yaak"));

View File

@@ -94,11 +94,6 @@ export const ResponsePane = memo(function ResponsePane({ style, className, activ
'shadow shadow-gray-100 dark:shadow-gray-0 relative', 'shadow shadow-gray-100 dark:shadow-gray-0 relative',
)} )}
> >
{activeResponse?.error && (
<Banner color="danger" className="m-2">
{activeResponse.error}
</Banner>
)}
{!activeResponse && ( {!activeResponse && (
<> <>
<span /> <span />
@@ -107,7 +102,7 @@ export const ResponsePane = memo(function ResponsePane({ style, className, activ
/> />
</> </>
)} )}
{activeResponse && !activeResponse.error && !isResponseLoading(activeResponse) && ( {activeResponse && !isResponseLoading(activeResponse) && (
<> <>
<HStack <HStack
alignItems="center" alignItems="center"
@@ -149,37 +144,43 @@ export const ResponsePane = memo(function ResponsePane({ style, className, activ
)} )}
</HStack> </HStack>
<Tabs {activeResponse?.error ? (
value={activeTab} <Banner color="danger" className="m-2 mt-4">
onChangeValue={setActiveTab} {activeResponse.error}
label="Response" </Banner>
tabs={tabs} ) : (
className="ml-3 mr-1" <Tabs
tabListClassName="mt-1.5" value={activeTab}
> onChangeValue={setActiveTab}
<TabContent value="headers"> label="Response"
<ResponseHeaders response={activeResponse} /> tabs={tabs}
</TabContent> className="ml-3 mr-1"
<TabContent value="body"> tabListClassName="mt-1.5"
{!activeResponse.contentLength ? ( >
<EmptyStateText>Empty Body</EmptyStateText> <TabContent value="headers">
) : contentType?.startsWith('image') ? ( <ResponseHeaders response={activeResponse} />
<ImageViewer className="pb-2" response={activeResponse} /> </TabContent>
) : activeResponse.contentLength > 2 * 1000 * 1000 ? ( <TabContent value="body">
<div className="text-sm italic text-gray-500"> {!activeResponse.contentLength ? (
Cannot preview text responses larger than 2MB <EmptyStateText>Empty Body</EmptyStateText>
</div> ) : contentType?.startsWith('image') ? (
) : viewMode === 'pretty' && contentType?.includes('html') ? ( <ImageViewer className="pb-2" response={activeResponse} />
<WebPageViewer response={activeResponse} /> ) : activeResponse.contentLength > 2 * 1000 * 1000 ? (
) : contentType?.match(/csv|tab-separated/) ? ( <div className="text-sm italic text-gray-500">
<CsvViewer className="pb-2" response={activeResponse} /> Cannot preview text responses larger than 2MB
) : ( </div>
// ) : contentType?.startsWith('application/json') ? ( ) : viewMode === 'pretty' && contentType?.includes('html') ? (
// <JsonViewer response={activeResponse} /> <WebPageViewer response={activeResponse} />
<TextViewer response={activeResponse} pretty={viewMode === 'pretty'} /> ) : contentType?.match(/csv|tab-separated/) ? (
)} <CsvViewer className="pb-2" response={activeResponse} />
</TabContent> ) : (
</Tabs> // ) : contentType?.startsWith('application/json') ? (
// <JsonViewer response={activeResponse} />
<TextViewer response={activeResponse} pretty={viewMode === 'pretty'} />
)}
</TabContent>
</Tabs>
)}
</> </>
)} )}
</div> </div>