mirror of
https://github.com/arun11299/cpp-jwt.git
synced 2025-05-31 08:57:43 +00:00
Added decode error codes and exceptions
This commit is contained in:
parent
234411a550
commit
9e69389caf
7 changed files with 131 additions and 18 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue