Commit eeb17c3f authored by luz's avatar luz

p44utils: Added TextError class for simple OK/Not OK status with textual error...

p44utils: Added TextError class for simple OK/Not OK status with textual error message in non-OK case
parent 4e8b623e
......@@ -162,3 +162,29 @@ ErrorPtr SysError::err(int aErrNo, const char *aContextMessage)
#pragma mark - web error
ErrorPtr WebError::err(uint16_t aHTTPError, std::string aErrorMessage)
{
if (aHTTPError==0)
return ErrorPtr(); // empty, no error
return ErrorPtr(new WebError(aHTTPError, aErrorMessage));
}
#pragma mark - text error
ErrorPtr TextError::err(const char *aFormat, ...)
{
va_list args;
va_start(args, aFormat);
// now make the string
string s;
string_format_v(s, true, aFormat, args);
va_end(args);
return ErrorPtr(new TextError(s));
}
......@@ -34,6 +34,7 @@ namespace p44 {
typedef enum {
ErrorOK,
ErrorNotOK
} CommonErrors;
......@@ -63,7 +64,7 @@ namespace p44 {
/// get error domain
/// @return the explicitly set error message, empty string if none is set.
/// @note use description() to get a text at least howing the error domain and code if no message is set
/// @note use description() to get a text at least showing the error domain and code if no message is set
virtual const char *getErrorMessage() const;
/// get error domain
......@@ -122,7 +123,24 @@ namespace p44 {
static const char *domain() { return "WebError"; }
virtual const char *getErrorDomain() const { return WebError::domain(); };
WebError(uint16_t aHTTPError) : Error(ErrorCode(aHTTPError)) {};
WebError(uint16_t aError, std::string aErrorMessage) : Error(ErrorCode(aError), aErrorMessage) {};
WebError(uint16_t aHTTPError, std::string aErrorMessage) : Error(ErrorCode(aHTTPError), aErrorMessage) {};
/// factory function to create a ErrorPtr either containing NULL (if aErrNo indicates OK)
/// or a SysError (if aErrNo indicates error)
static ErrorPtr err(uint16_t aHTTPError, std::string aErrorMessage);
};
/// Text message based error
class TextError : public Error
{
public:
static const char *domain() { return "TextError"; }
virtual const char *getErrorDomain() const { return TextError::domain(); };
TextError(std::string aErrorMessage) : Error(ErrorNotOK, aErrorMessage) {};
/// factory method to create string error fprint style
static ErrorPtr err(const char *aFormat, ...);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment