Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #130 from modio-jackson/error_ref-logging
Browse files Browse the repository at this point in the history
error_ref implementation
  • Loading branch information
Turupawn authored Jul 1, 2020
2 parents f0e9639 + 4c242bc commit 9d0156d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/c++/schemas/Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Error
{
public:
u32 code;
u32 error_ref;
std::string message;
std::vector<std::string> errors;

Expand Down
1 change: 1 addition & 0 deletions include/c/ModioC.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ extern "C"
struct ModioError
{
u32 code;
u32 error_ref;
char* message;
char** errors_array;
u32 errors_array_size;
Expand Down
6 changes: 4 additions & 2 deletions src/c++/schemas/Error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace modio
void Error::initialize(ModioError modio_error)
{
code = modio_error.code;
error_ref = modio_error.error_ref;
if (modio_error.message)
message = modio_error.message;
errors.resize(modio_error.errors_array_size);
Expand All @@ -21,15 +22,16 @@ nlohmann::json toJson(Error &error)
nlohmann::json error_json;

error_json["code"] = error.code;
error_json["error_ref"] = error.error_ref;
error_json["message"] = error.message;

nlohmann::json errors_json;

for (u32 i = 0; i<error.errors.size(); i++)
{
errors_json.push_back(error.errors[i]);
}

error_json["errors"] = errors_json;

return error_json;
Expand Down
5 changes: 5 additions & 0 deletions src/c/schemas/ModioError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ extern "C"
if(modio::hasKey(error_json, "code"))
error->code = error_json["code"];

error->error_ref = 0;
if(modio::hasKey(error_json, "error_ref"))
error->error_ref = error_json["error_ref"];

error->message = NULL;
if(modio::hasKey(error_json, "message"))
{
Expand Down Expand Up @@ -44,6 +48,7 @@ extern "C"
void modioInitErrorCpp(ModioError* modio_error, modio::Error* error)
{
modio_error->code = error->code;
modio_error->error_ref = error->error_ref;

modio_error->message = new char[error->message.size() + 1];
strcpy(modio_error->message, error->message.c_str());
Expand Down

0 comments on commit 9d0156d

Please sign in to comment.