Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Commit

Permalink
fix: 502 replica errors + map DESTINATION_INVALID to 404 (#43)
Browse files Browse the repository at this point in the history
This should map any `canister has no query method 'http_request'` or `canister not found` to `404`. 

Also change from `500` to `502` for replica errors.
  • Loading branch information
Daniel-Bloom-dfinity authored Jul 29, 2022
1 parent 02a0517 commit a90e666
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ const MB: usize = 1024 * KB;
const REQUEST_BODY_SIZE_LIMIT: usize = 10 * MB;
const RESPONSE_BODY_SIZE_LIMIT: usize = 10 * MB;

/// https://internetcomputer.org/docs/current/references/ic-interface-spec#reject-codes
struct ReplicaErrorCodes;
impl ReplicaErrorCodes {
const DESTINATION_INVALID: u64 = 3;
}

/// Resolve overrides for [`reqwest::ClientBuilder::resolve()`]
/// `ic0.app=[::1]:9090`
pub(crate) struct OptResolve {
Expand Down Expand Up @@ -270,11 +276,19 @@ async fn forward_request(
match result {
Ok((http_response,)) => Ok(http_response),

Err(AgentError::ReplicaError {
reject_code: ReplicaErrorCodes::DESTINATION_INVALID,
reject_message,
}) => Err(Ok(Response::builder()
.status(StatusCode::NOT_FOUND)
.body(reject_message.into())
.unwrap())),

Err(AgentError::ReplicaError {
reject_code,
reject_message,
}) => Err(Ok(Response::builder()
.status(StatusCode::INTERNAL_SERVER_ERROR)
.status(StatusCode::BAD_GATEWAY)
.body(format!(r#"Replica Error ({}): "{}""#, reject_code, reject_message).into())
.unwrap())),

Expand Down

0 comments on commit a90e666

Please sign in to comment.