Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #51 #53

Merged
merged 5 commits into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading