-
Notifications
You must be signed in to change notification settings - Fork 84
Open
Description
Hi, great library, I'm enjoying it. I would like to somehow support the ?
operator in my actix-web app. The actix-web HTTP handler's support a Result<_,_>
return value so that means ?
will work, but the Err variant needs to implement their ResponseError trait: https://github.com/actix/actix-web/blob/master/actix-web/src/error/response_error.rs .
I can't implement ResponseError for eyre::Result because of the orphan rule. Any tips on how I could use eyre::Result in this scenario? And food for thought, here is how I hacked some existing code to use the stdlib Result in actix-web:
use actix_web::ResponseError;
use std::fmt::{Display, Formatter};
#[derive(Debug)]
pub struct WebError {}
impl Display for WebError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "WebError{{}}")
}
}
impl ResponseError for WebError {}
#[get("/exports/{id}/run")]
pub async fn exports_run(id: Identity, req: HttpRequest) -> Result<HttpResponse, WebError> {
let identity = id.identity().unwrap();
let pg_conn = pg_conn();
let id = req.match_info().get("id").unwrap();
let id: i32 = id.parse().map_err(|_| WebError {})?;
let job: ExportJob = export_jobs::table
.filter(export_jobs_dsl::identity.eq(&identity))
.filter(export_jobs_dsl::id.eq(id))
.first::<ExportJob>(&pg_conn)
.map_err(|_| WebError {})?;
let athena_query = sparkle_athena::StreamableAthenaResult {
athena_database: job.athena_database,
athena_view: job.athena_view,
};
let csv = execute_query(athena_query).await.map_err(|_| WebError {})?;
let mut oauth2_token = oauth_tokens_dsl::oauth2_tokens
.filter(oauth_tokens_dsl::identity.eq(&identity))
.first::<OAuth2Token>(&pg_conn)
.map_err(|_| WebError {})?;
oauth2_token
.refresh(&pg_conn)
.await
.map_err(|_| WebError {})?;
Ok(HttpResponse::Ok().body("not implemented yet"))
}
jackykwe and siedentop
Metadata
Metadata
Assignees
Labels
No labels