Skip to content

Commit

Permalink
Merge pull request #47 from internet-computer-protocol/cycles-error
Browse files Browse the repository at this point in the history
Enhance `TooFewCycles` error
  • Loading branch information
rvanasa authored Sep 25, 2023
2 parents 45211c6 + 69932eb commit a272c4b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion candid/ic_eth.did
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ type Auth = variant { Rpc; RegisterProvider; FreeRpc; Admin };
type EthRpcError = variant {
ServiceUrlHostNotAllowed;
HttpRequestError : record { code : nat32; message : text };
TooFewCycles : text;
TooFewCycles : record { expected : nat; received : nat };
ServiceUrlParseError;
ServiceUrlHostMissing;
ProviderNotFound;
Expand Down
7 changes: 4 additions & 3 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ pub async fn do_http_request(
}
if !is_authorized(Auth::FreeRpc) {
if cycles_available < cost {
return Err(EthRpcError::TooFewCycles(format!(
"requires {cost} cycles, got {cycles_available} cycles",
)));
return Err(EthRpcError::TooFewCycles {
expected: cost,
received: cycles_available,
});
}
ic_cdk::api::call::msg_cycles_accept128(cost);
if let Some(mut provider) = provider {
Expand Down
2 changes: 1 addition & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl BoundedStorable for Provider {
#[derive(CandidType, Debug)]
pub enum EthRpcError {
NoPermission,
TooFewCycles(String),
TooFewCycles { expected: u128, received: u128 },
ServiceUrlParseError,
ServiceUrlHostMissing,
ServiceUrlHostNotAllowed,
Expand Down

0 comments on commit a272c4b

Please sign in to comment.