[FE] Fixes #38: Use axios. Fix error not showing on Scans

master
Araozu 2023-12-13 09:56:44 -05:00
parent ad7d224207
commit ffb7518ef6
3 changed files with 28 additions and 28 deletions

View File

@ -70,7 +70,7 @@ fn get_valid_files() -> Result<Vec<PathBuf>, String> {
Ok(paths) => paths, Ok(paths) => paths,
Err(err) => { Err(err) => {
log::error!("Error reading dir: {:?}", err); log::error!("Error reading dir: {:?}", err);
return Err("Error leyendo directorio".into()); return Err("Error abriendo carpeta ESCANEOS".into());
} }
}; };
@ -81,7 +81,7 @@ fn get_valid_files() -> Result<Vec<PathBuf>, String> {
Ok(p) => p, Ok(p) => p,
Err(err) => { Err(err) => {
log::error!("Error reading path: {:?}", err); log::error!("Error reading path: {:?}", err);
return Err("Error recuperando archivo de lista de archivos".into()); return Err("Error leyendo archivos en ESCANEOS".into());
} }
}; };
@ -96,7 +96,7 @@ fn get_valid_files() -> Result<Vec<PathBuf>, String> {
Some(filename) => filename, Some(filename) => filename,
None => { None => {
log::error!("Error getting file name: {:?}", file_path); log::error!("Error getting file name: {:?}", file_path);
return Err("Error leyendo archivo en directorio".into()); return Err("Error leyendo archivo en ESCANEOS".into());
} }
}; };
@ -162,7 +162,7 @@ fn get_image_info(path: PathBuf) -> ScanInfo {
let current_time = match current_time { let current_time = match current_time {
Ok(t) => t, Ok(t) => t,
Err(err) => { Err(err) => {
log::error!("Error obteniendo hora actual: {:?}", err); log::error!("Error getting time, TIME WENT BACKWARDS: {:?}", err);
return ScanInfo::Error("Error obteniendo hora actual: TIME WENT BACKWARDS.".into()); return ScanInfo::Error("Error obteniendo hora actual: TIME WENT BACKWARDS.".into());
} }
}; };
@ -191,7 +191,7 @@ fn get_image_info(path: PathBuf) -> ScanInfo {
// If no QR is detected, only rename // If no QR is detected, only rename
if results.is_empty() { if results.is_empty() {
log::info!("QR not found"); log::info!("QR not found, only renaming");
// Rename file // Rename file
let mut new_path = path.clone(); let mut new_path = path.clone();
@ -202,7 +202,7 @@ fn get_image_info(path: PathBuf) -> ScanInfo {
Err(err) => { Err(err) => {
log::error!("Error renombrando archivo: {:?}", err); log::error!("Error renombrando archivo: {:?}", err);
ScanInfo::Error("Error renombrando archivo.".into()) ScanInfo::Error("Error renombrando archivo sin QR detectado.".into())
} }
}; };
} }
@ -222,7 +222,7 @@ fn get_image_info(path: PathBuf) -> ScanInfo {
Err(err) => { Err(err) => {
log::error!("Error renombrando archivo: {:?}", err); log::error!("Error renombrando archivo: {:?}", err);
ScanInfo::Error("Error renombrando archivo.".into()) ScanInfo::Error("Error renombrando archivo sin QR detectado.".into())
} }
}; };
} }
@ -241,7 +241,7 @@ fn get_image_info(path: PathBuf) -> ScanInfo {
Some(p) => p, Some(p) => p,
None => { None => {
return ScanInfo::Error( return ScanInfo::Error(
"QR invalido: Tiene signo de interrogacion (?) pero no igual (=).".into(), "QR invalido: La URL tiene signo de interrogacion (?) pero no igual (=).".into(),
) )
} }
}; };
@ -264,7 +264,7 @@ fn get_image_info(path: PathBuf) -> ScanInfo {
} }
} }
} }
Err(_) => ScanInfo::Error("QR invalido: El iid no es un número.".into()), Err(_) => ScanInfo::Error("QR invalido: El iid de la URL no es un número.".into()),
} }
} }
None => { None => {
@ -320,7 +320,7 @@ async fn convert_scans_from_data(data: &Vec<ScanInfo>) -> Result<(), String> {
Ok(v) => v, Ok(v) => v,
Err(err) => { Err(err) => {
log::error!("Error getting persons info: {:?}", err); log::error!("Error getting persons info: {:?}", err);
return Err("Error obteniendo información de personas.".into()); return Err(format!("Error obteniendo información de personas. {}", err));
} }
}; };
@ -436,7 +436,7 @@ fn convert_to_pdf(image_path: &PathBuf, output_path: &PathBuf) -> Result<(), Str
Ok(r) => r, Ok(r) => r,
Err(err) => { Err(err) => {
log::error!("Error starting imagemagick: {:?}", err); log::error!("Error starting imagemagick: {:?}", err);
return Err(format!("Error convirtiendo imagen")); return Err(format!("Error inicializando ImageMagick"));
} }
}; };
@ -445,12 +445,12 @@ fn convert_to_pdf(image_path: &PathBuf, output_path: &PathBuf) -> Result<(), Str
Ok(exit_status) => { Ok(exit_status) => {
log::error!("Error calling imagemagick: {:?}", exit_status); log::error!("Error calling imagemagick: {:?}", exit_status);
Err(format!( Err(format!(
"Error ejecutando imagemagick: codigo de salida no exitoso" "Error ejecutando ImageMagick: codigo de salida no exitoso"
)) ))
} }
Err(err) => { Err(err) => {
log::error!("Error calling imagemagick: {:?}", err); log::error!("Error calling imagemagick: {:?}", err);
Err(format!("Error ejecutando imagemagick")) Err(format!("Error ejecutando ImageMagick"))
} }
} }
} }

View File

@ -253,7 +253,6 @@ impl Register {
let result = match db.fetch_all(sql.as_str()).await { let result = match db.fetch_all(sql.as_str()).await {
Ok(res) => res, Ok(res) => res,
Err(err) => { Err(err) => {
drop(sqlx::Error::PoolTimedOut);
log::error!("Error fetching course & person: {:?}", err); log::error!("Error fetching course & person: {:?}", err);
return Err("Error fetching course & person".into()); return Err("Error fetching course & person".into());
} }

View File

@ -6,6 +6,8 @@ import { LoadingIcon } from "../icons/LoadingIcon";
import { PDFIcon } from "../icons/PDFIcon"; import { PDFIcon } from "../icons/PDFIcon";
import { LoadingStatus, useLoading } from "../utils/functions"; import { LoadingStatus, useLoading } from "../utils/functions";
import { QuestionIcon } from "../icons/QuestionIcon"; import { QuestionIcon } from "../icons/QuestionIcon";
import axios from "axios";
import { JsonResult } from "../types/JsonResult";
export function ScansList(props: {scanData: Array<ScanResult> | null, onSuccess: () => void}) { export function ScansList(props: {scanData: Array<ScanResult> | null, onSuccess: () => void}) {
const {status, setStatus, error, setError} = useLoading(); const {status, setStatus, error, setError} = useLoading();
@ -45,24 +47,21 @@ export function ScansList(props: {scanData: Array<ScanResult> | null, onSuccess:
return; return;
} }
fetch( axios.post(`${import.meta.env.VITE_BACKEND_URL}/api/scans/convert`, props.scanData)
`${import.meta.env.VITE_BACKEND_URL}/api/scans/convert`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(props.scanData),
},
)
.then((res) => res.json())
.then(() => { .then(() => {
setStatus(LoadingStatus.Ok); setStatus(LoadingStatus.Ok);
props.onSuccess(); props.onSuccess();
}) })
.catch((err) => { .catch((err) => {
setStatus(LoadingStatus.Error);
console.error(err); console.error(err);
setStatus(LoadingStatus.Error);
if (err.response.data) {
const errorData = err.response.data as JsonResult<null>;
console.error(errorData);
console.error(errorData.Error.reason);
setError(errorData.Error.reason);
}
}); });
}; };
@ -158,8 +157,10 @@ export function ScansList(props: {scanData: Array<ScanResult> | null, onSuccess:
<Show when={status() === LoadingStatus.Error}> <Show when={status() === LoadingStatus.Error}>
<div class="px-4 pb-4"> <div class="px-4 pb-4">
<p class="font-medium"> <p class="font-medium text-c-error bg-c-on-error p-1 rounded-md">
Error convirtiendo PDFs: {error()} Error fatal convirtiendo PDFs:
<br />
{error()}
</p> </p>
</div> </div>
</Show> </Show>