Added decode error codes and exceptions

This commit is contained in:
Arun M 2017-12-04 13:17:48 +05:30
parent 234411a550
commit 9e69389caf
7 changed files with 131 additions and 18 deletions

View file

@ -30,9 +30,38 @@ struct AlgorithmErrCategory: std::error_category
}
};
/**
*/
struct DecodeErrorCategory: std::error_category
{
const char* name() const noexcept override
{
return "decode";
}
std::string message(int ev) const override
{
switch (static_cast<DecodeErrc>(ev))
{
case DecodeErrc::AlgHeaderMiss:
return "missing algorithm header";
case DecodeErrc::TypHeaderMiss:
return "missing type header";
case DecodeErrc::TypMismatch:
return "type mismatch";
case DecodeErrc::JsonParseError:
return "json parse failed";
};
assert (0 && "Code not reached");
}
};
// Create global object for the error categories
const AlgorithmErrCategory theAlgorithmErrCategory {};
const DecodeErrorCategory theDecodeErrorCategory {};
}
@ -42,6 +71,11 @@ std::error_code make_error_code(AlgorithmErrc err)
return { static_cast<int>(err), theAlgorithmErrCategory };
}
std::error_code make_error_code(DecodeErrc err)
{
return { static_cast<int>(err), theDecodeErrorCategory };
}
} // END namespace jwt