error.rs 708 B

123456789101112131415161718192021222324252627
  1. use serde_json::Value;
  2. use darkfi::rpc::{
  3. jsonrpc,
  4. jsonrpc::{ErrorCode::ServerError, JsonResult},
  5. };
  6. pub enum RpcError {
  7. AmountExceedsLimit = -32107,
  8. TimeLimitReached = -32108,
  9. ParseError = -32109,
  10. }
  11. fn to_tuple(e: RpcError) -> (i64, String) {
  12. let msg = match e {
  13. RpcError::AmountExceedsLimit => "Amount requested is higher than the faucet limit",
  14. RpcError::TimeLimitReached => "Timeout not expired. Try again later",
  15. RpcError::ParseError => "Parse error",
  16. };
  17. (e as i64, msg.to_string())
  18. }
  19. pub fn server_error(e: RpcError, id: Value) -> JsonResult {
  20. let (code, msg) = to_tuple(e);
  21. jsonrpc::error(ServerError(code), Some(msg), id).into()
  22. }