Skip to content

Commit

Permalink
Merge pull request #61 from dfinity/igornovg/fix-crash-v2
Browse files Browse the repository at this point in the history
Fix error-cause-related crash, update deps
  • Loading branch information
r-birkner authored Jan 20, 2025
2 parents 47b64a0 + 18b4064 commit 0f307a9
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 49 deletions.
91 changes: 46 additions & 45 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/routing/error_cause.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,16 @@ impl ErrorClientFacing {
// Creates the response from ErrorClientFacing
impl IntoResponse for ErrorClientFacing {
fn into_response(self) -> Response {
let error_context = ERROR_CONTEXT.get();
let request_type = ERROR_CONTEXT.try_with(|x| *x).unwrap_or_default();

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

let mut resp = (self.status_code(), body).into_response();
if error_context == RequestType::Http {
if request_type == RequestType::Http {
resp.headers_mut().insert(CONTENT_TYPE, CONTENT_TYPE_HTML);
}
resp
Expand Down
5 changes: 4 additions & 1 deletion src/routing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,17 @@ impl From<CanisterId> for Principal {
}
}

#[derive(Debug, Clone, Copy, Display, PartialEq, Eq, PartialOrd, Ord, Hash, IntoStaticStr)]
#[derive(
Debug, Default, Clone, Copy, Display, PartialEq, Eq, PartialOrd, Ord, Hash, IntoStaticStr,
)]
#[strum(serialize_all = "snake_case")]
pub enum RequestType {
Http,
Health,
Registrations,
#[strum(to_string = "{0}")]
Api(RequestTypeApi),
#[default]
Unknown,
}

Expand Down

0 comments on commit 0f307a9

Please sign in to comment.