1#![deny(unsafe_code)]
2#![warn(missing_docs)]
3pub mod error;
9
10pub use error::{XrpcError, XrpcErrorName};
11
12use axum::response::IntoResponse;
13use axum::routing::any;
14use axum::Router;
15
16pub fn xrpc_router<S: Clone + Send + Sync + 'static>() -> Router<S> {
26 Router::new().fallback(any(xrpc_fallback))
27}
28
29async fn xrpc_fallback() -> impl IntoResponse {
31 XrpcError {
32 name: XrpcErrorName::MethodNotImplemented,
33 message: "XRPC method not implemented".to_string(),
34 }
35}
36
37pub fn xrpc_invalid_request(msg: impl Into<String>) -> XrpcError {
39 XrpcError {
40 name: XrpcErrorName::InvalidRequest,
41 message: msg.into(),
42 }
43}
44
45pub fn xrpc_auth_required(msg: impl Into<String>) -> XrpcError {
47 XrpcError {
48 name: XrpcErrorName::AuthRequired,
49 message: msg.into(),
50 }
51}
52
53pub fn xrpc_forbidden(msg: impl Into<String>) -> XrpcError {
55 XrpcError {
56 name: XrpcErrorName::Forbidden,
57 message: msg.into(),
58 }
59}
60
61pub fn xrpc_not_found(msg: impl Into<String>) -> XrpcError {
63 XrpcError {
64 name: XrpcErrorName::NotFound,
65 message: msg.into(),
66 }
67}
68
69pub fn xrpc_rate_limit(msg: impl Into<String>) -> XrpcError {
71 XrpcError {
72 name: XrpcErrorName::RateLimitExceeded,
73 message: msg.into(),
74 }
75}