[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,
Err(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,
Err(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,
None => {
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 {
Ok(t) => t,
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());
}
};
@ -191,7 +191,7 @@ fn get_image_info(path: PathBuf) -> ScanInfo {
// If no QR is detected, only rename
if results.is_empty() {
log::info!("QR not found");
log::info!("QR not found, only renaming");
// Rename file
let mut new_path = path.clone();
@ -202,7 +202,7 @@ fn get_image_info(path: PathBuf) -> ScanInfo {
Err(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) => {
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,
None => {
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 => {
@ -320,7 +320,7 @@ async fn convert_scans_from_data(data: &Vec<ScanInfo>) -> Result<(), String> {
Ok(v) => v,
Err(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,
Err(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) => {
log::error!("Error calling imagemagick: {:?}", exit_status);
Err(format!(
"Error ejecutando imagemagick: codigo de salida no exitoso"
"Error ejecutando ImageMagick: codigo de salida no exitoso"
))
}
Err(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 {
Ok(res) => res,
Err(err) => {
drop(sqlx::Error::PoolTimedOut);
log::error!("Error fetching course & person: {:?}", err);
return Err("Error fetching course & person".into());
}

View File

@ -6,6 +6,8 @@ import { LoadingIcon } from "../icons/LoadingIcon";
import { PDFIcon } from "../icons/PDFIcon";
import { LoadingStatus, useLoading } from "../utils/functions";
import { QuestionIcon } from "../icons/QuestionIcon";
import axios from "axios";
import { JsonResult } from "../types/JsonResult";
export function ScansList(props: {scanData: Array<ScanResult> | null, onSuccess: () => void}) {
const {status, setStatus, error, setError} = useLoading();
@ -45,24 +47,21 @@ export function ScansList(props: {scanData: Array<ScanResult> | null, onSuccess:
return;
}
fetch(
`${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())
axios.post(`${import.meta.env.VITE_BACKEND_URL}/api/scans/convert`, props.scanData)
.then(() => {
setStatus(LoadingStatus.Ok);
props.onSuccess();
})
.catch((err) => {
setStatus(LoadingStatus.Error);
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}>
<div class="px-4 pb-4">
<p class="font-medium">
Error convirtiendo PDFs: {error()}
<p class="font-medium text-c-error bg-c-on-error p-1 rounded-md">
Error fatal convirtiendo PDFs:
<br />
{error()}
</p>
</div>
</Show>