Skip to content

Commit

Permalink
Removed 500 gateway response #18
Browse files Browse the repository at this point in the history
* the handler returns an empty error struct for the runtime to record as an error and log in CloudWatch
* these errors should show up in monitoring
  • Loading branch information
rimutaka committed Feb 1, 2022
1 parent 9723887 commit 734eee0
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion stm_html_ui/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ struct ApiGatewayRequest {
#[folder = "templates"]
struct Asset;

/// A blank error structure to return to the runtime. No messages are required because all necessary information has already been logged.
/// The API Gateway will return 500 which may be picked up by CloudFront and converted into a nice looking 500 page.
#[derive(Debug, Serialize)]
struct HandlerError {}

impl std::error::Error for HandlerError {}

impl std::fmt::Display for HandlerError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "")
}
}

//pub(crate) async fn my_handler(event: Value, _ctx: Context) -> Result<Value, Error> {
pub(crate) async fn my_handler(event: Value, _ctx: Context) -> Result<Value, Error> {
let mut sys = System::new_with_specifics(RefreshKind::with_memory(RefreshKind::new()));
Expand Down Expand Up @@ -94,7 +107,7 @@ pub(crate) async fn my_handler(event: Value, _ctx: Context) -> Result<Value, Err
// send the user request downstream for processing
let html_data = match html::html(&config, url_path, url_query, dev, api_request.headers).await {
Ok(v) => v,
Err(_) => return gw_response("Server Error".to_owned(), 500, 600),
Err(_) => return Err(Box::new(HandlerError {})),
};

log_memory_use(&mut sys, "HTML data returned");
Expand Down

0 comments on commit 734eee0

Please sign in to comment.