surrealdb_core/rpc/
error.rs1use thiserror::Error;
2
3use crate::err;
4
5#[derive(Debug, Error)]
6#[non_exhaustive]
7pub enum RpcError {
8 #[error("Parse error")]
9 ParseError,
10 #[error("Invalid request")]
11 InvalidRequest,
12 #[error("Method not found")]
13 MethodNotFound,
14 #[error("Method not allowed")]
15 MethodNotAllowed,
16 #[error("Invalid params")]
17 InvalidParams,
18 #[error("There was a problem with the database: {0}")]
19 InternalError(err::Error),
20 #[error("Live Query was made, but is not supported")]
21 LqNotSuported,
22 #[error("RT is enabled for the session, but LQ is not supported by the context")]
23 BadLQConfig,
24 #[error("A GraphQL request was made, but GraphQL is not supported by the context")]
25 BadGQLConfig,
26 #[error("Error: {0}")]
27 Thrown(String),
28}
29
30impl From<err::Error> for RpcError {
31 fn from(e: err::Error) -> Self {
32 use err::Error;
33 match e {
34 Error::RealtimeDisabled => RpcError::LqNotSuported,
35 _ => RpcError::InternalError(e),
36 }
37 }
38}
39
40impl From<&str> for RpcError {
41 fn from(e: &str) -> Self {
42 RpcError::Thrown(e.to_string())
43 }
44}
45
46impl From<RpcError> for err::Error {
47 fn from(value: RpcError) -> Self {
48 use err::Error;
49 match value {
50 RpcError::InternalError(e) => e,
51 RpcError::Thrown(e) => Error::Thrown(e),
52
53 _ => Error::Thrown(value.to_string()),
54 }
55 }
56}