fix: return 404 if api returns 404 (cv user not exists)

This commit is contained in:
Ondrej Vlach 2023-12-11 22:19:06 +01:00
parent b7b3957db8
commit ebe46345fe
Signed by: ovlach
GPG Key ID: 4FF1A23B4914DE70

View File

@ -3,13 +3,14 @@ use headless_chrome::types::PrintToPdfOptions;
use nanobyte_opentelemetry::rocket::{TracingSpan, OtelReqwestClient};
use nanobyte_tera::l18n::LanguageDescription;
use ovlach_data::cv::data::CV;
use reqwest::StatusCode;
use rocket::fs::NamedFile;
use rocket::serde::json::json;
use ::rocket::{State, http::Status};
use ::rocket::get;
use tempfile::NamedTempFile;
use tera::Context;
use tracing::{info_span, error, debug, Instrument};
use tracing::{info_span, error, debug, Instrument, info};
use crate::tools::cache::NanoCache;
use crate::{chromium::rocket::BrowserHolder, tools::{tera::NanoTera, pdf::PdfStream, rocket::RequestLanguage}, services::cv::fetch_cv_data_from_backend, CVBackendConfig};
@ -86,8 +87,24 @@ pub async fn render_pdf_cv(username: &str, tera: NanoTera, tracing: TracingSpan,
}
},
Err(e) => {
error!("Error fetching cv data: {:?}", e);
Err(Status::InternalServerError)
match e {
crate::services::cv::FetchError::ReqwestError(re) => {
match re.status() {
Some(status) => {
if status == StatusCode::NOT_FOUND {
info!("CV not found for user {}", username);
Err(Status::NotFound)
} else {
Err(Status::InternalServerError)
}
}
None => {
error!("Error fetching cv data: {:?}", re);
Err(Status::InternalServerError)
},
}
}
}
}
}
}.instrument(tracing.0).await