Skip to content

Commit

Permalink
addressing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
r-birkner committed Dec 13, 2024
1 parent 8dbb31b commit d43134f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
9 changes: 6 additions & 3 deletions src/routing/error_cause.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ impl ErrorClientFacing {
_ => {
let template = ERROR_PAGE_TEMPLATE;
let template = template.replace("{status_code}", self.status_code().as_str());
let template = template.replace("{reason}", self.to_string().as_str());
let template =
template.replace("{reason}", self.to_string().replace("_", " ").as_str());
let template = template.replace("{details}", self.details().as_str());
template
}
Expand All @@ -293,14 +294,16 @@ impl ErrorClientFacing {
// Creates the response from ErrorClientFacing
impl IntoResponse for ErrorClientFacing {
fn into_response(self) -> Response {
let error_context = ERROR_CONTEXT.get();

// Return an HTML error page if it was an HTTP request
let body = match ERROR_CONTEXT.get() {
let body = match error_context {
RequestType::Http => format!("{}\n", self.html()),
_ => format!("error: {}\ndetails: {}", self.to_string(), self.details()),
};

let mut resp = (self.status_code(), body).into_response();
if ERROR_CONTEXT.get() == RequestType::Http {
if error_context == RequestType::Http {
resp.headers_mut().insert(CONTENT_TYPE, CONTENT_TYPE_HTML);
}
resp
Expand Down
4 changes: 2 additions & 2 deletions src/routing/error_pages/451.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ <h3 class="transparent">This app is powered by</h3>

<!-- 451 Notice -->
<div>
<h1>451 (Unavailable for policy reasons)</h1>
<h1>451 - unavailable for policy reasons)</h1>
<h3>
<strong>
The page you are looking for is currently being blocked.
Expand Down Expand Up @@ -245,4 +245,4 @@ <h3>
</main>
</body>

</html>
</html>
12 changes: 7 additions & 5 deletions src/routing/ic/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ pub async fn handler(

let ic_status = IcResponseStatus::from(&resp);

// Convert it into Axum response
let mut response = match resp.metadata.internal_error {
None => resp.canister_response.into_response(),
Some(e) => return Err(ErrorCause::HttpGatewayError(e)),
};
// Check if an error occured in the HTTP gateway library
if let Some(e) = resp.metadata.internal_error {
return Err(ErrorCause::HttpGatewayError(e));
}

// Convert the HTTP gateway library response into an Axum response
let mut response = resp.canister_response.into_response();
response.extensions_mut().insert(ic_status);
response.extensions_mut().insert(bn_req_meta);
response.extensions_mut().insert(bn_resp_meta);
Expand Down

0 comments on commit d43134f

Please sign in to comment.