Skip to content

Commit

Permalink
Fix issue #51 (#53)
Browse files Browse the repository at this point in the history
* Agrega verificacion de si existe el enum

* Actualiza la condicion del rango y el requisito

* Hace la asignacion de limites un poco mas legible

* Minor fixes (chatgpt malo)
  • Loading branch information
ffpp2003 authored Nov 7, 2024
1 parent 7b860fe commit efaaa8e
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,32 @@
enum errorCode{
OK,
//Database errors
DB_CLIENT_NOT_FOUND = 1,
DB_LI = 1,
DB_CLIENT_NOT_FOUND = DB_LI,
DB_VEHICLE_NOT_FOUND,
DB_DUPLICATE_CLIENT,
DB_DUPLICATE_VEHICLE,
DB_LS = DB_DUPLICATE_VEHICLE,
//Client Errors
CL_SERVER_TIMEOUT = 100,
CL_LI = 100,
CL_SERVER_TIMEOUT = CL_LI,
CL_LS = CL_SERVER_TIMEOUT,
//Vehicle Errors
VH_CLIENT_ASSOCIATE = 200,
VH_LI = 200,
VH_CLIENT_ASSOCIATE = VH_LI,
VH_LS = VH_CLIENT_ASSOCIATE,
//Terminal errors (for)
TR_NOT_ENOUGH_FUNDS = 300,
TR_JUST_ENOUGH_FUNDS,
TR_CLIENT_NOT_FOUND,
};

// enumRange es el rango en donde hay enums definidos, donde se consideran
// pares de numeros para el rango, siendo el primero el limite inferior y
// el segundo el limite superior (NO EXCLUYENTES). "errLib" debe contener
// al menos una cadena vacia para asignar un espacio en el arreglo. En caso
// de no tener cadenas, el rango de aquellas debera ser excluido de enumRange
const int enumRange[] = {DB_LI, DB_LS, CL_LI, CL_LS, VH_LI, VH_LS};

const std::string errLib[][99] = {
{
Expand All @@ -45,7 +57,18 @@ const std::string errLib[][99] = {
}
};

inline std::string getErrMsg(int error){
bool checkEnumRange(int error){
for(int i = 0; i<(sizeof(enumRange)/sizeof(*enumRange)); i += 2) {
if(enumRange[i] <= error && enumRange[i+1] >= error)
return true;
}
return false;
}

std::string getErrMsg(int error){
if (checkEnumRange(error) == 0)
return "NO_ERR_MSG";

int errType = error / 100;
int errId = error % 100;
return errLib[errType][errId];
Expand Down

0 comments on commit efaaa8e

Please sign in to comment.