error.rs 700 B

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