feat!: start implementing repo listing & auth middleware

This commit is contained in:
2026-01-15 00:20:14 -08:00
parent 92d409f812
commit 6f2f64fd73
18 changed files with 1982 additions and 21 deletions

39
api/src/error.rs Normal file
View File

@@ -0,0 +1,39 @@
use actix_web::{HttpResponse, ResponseError, http::StatusCode};
use serde::Serialize;
use thiserror::Error;
pub type Result<T> = core::result::Result<T, Error>;
#[derive(Debug, Error)]
pub enum Error {
#[error("db error: {0}")]
DB(#[from] sqlx::Error),
#[error("http error: {0}")]
Http(#[from] reqwest::Error),
#[error("error getting access token")]
AccessToken,
#[error("unauthorized")]
Unauthorized,
#[error("jwx error")]
Jwx(#[from] jsonwebtoken::errors::Error),
#[error("token expired")]
TokenExpired,
}
#[derive(Serialize)]
struct ErrorResponse {
error: String,
}
impl ResponseError for Error {
fn error_response(&self) -> actix_web::HttpResponse<actix_web::body::BoxBody> {
match self {
Error::AccessToken => HttpResponse::Unauthorized().finish(),
Error::Unauthorized => HttpResponse::Unauthorized().finish(),
Error::TokenExpired => HttpResponse::Unauthorized().json(ErrorResponse {
error: "token expired".to_string(),
}),
_ => HttpResponse::InternalServerError().finish(),
}
}
}