tracks lexicons and how many times they appeared on the jetstream
1use std::fmt::Display;
2
3use axum::{Json, http::StatusCode, response::IntoResponse};
4use serde::Serialize;
5
6#[derive(Debug)]
7pub struct AppError {
8 inner: anyhow::Error,
9}
10
11impl Display for AppError {
12 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
13 write!(f, "{}", self.inner)
14 }
15}
16
17impl<E> From<E> for AppError
18where
19 E: Into<anyhow::Error>,
20{
21 fn from(err: E) -> Self {
22 Self { inner: err.into() }
23 }
24}
25
26#[derive(Serialize)]
27struct ErrorBody {
28 error: String,
29}
30impl IntoResponse for AppError {
31 fn into_response(self) -> axum::response::Response {
32 (
33 StatusCode::INTERNAL_SERVER_ERROR,
34 Json(ErrorBody {
35 error: self.inner.to_string(),
36 }),
37 )
38 .into_response()
39 }
40}
41
42pub type AppResult<T> = Result<T, AppError>;