Fledge
An open source edge computing platform for industrial users
omferror.h
1 #ifndef _OMFERROR_H
2 #define _OMFERROR_H
3 /*
4  * Fledge OSIsoft OMF interface to PI Server.
5  *
6  * Copyright (c) 2023 Dianomic Systems
7  *
8  * Released under the Apache 2.0 Licence
9  *
10  * Author: Mark Riddoch
11  */
12 
13 #include <rapidjson/document.h>
14 #include <string>
15 #include <vector>
16 
21 class OMFError {
22  public:
23  OMFError();
24  OMFError(const std::string& json);
25  ~OMFError();
26 
27  unsigned int messageCount() { return m_messages.size(); };
28  std::string getMessage(unsigned int offset);
29  std::string getEventReason(unsigned int offset);
30  std::string getEventSeverity(unsigned int offset);
31  std::string getEventExceptionType(unsigned int offset);
32  std::string getEventExceptionMessage(unsigned int offset);
33  int getHttpCode();
34  void setFromHttpResponse(const std::string& json);
38  bool hasErrors() { return m_hasErrors; };
42  bool hasMessages() { return !m_messages.empty(); };
43  bool Log(const std::string &mainMessage, bool filterDuplicates = true);
44  private:
45  class Message {
46  public:
47  Message(const std::string& severity,
48  const std::string& message,
49  const std::string& reason,
50  const std::string& exceptionType,
51  const std::string& exceptionMessage,
52  const int httpCode) :
53  m_severity(severity),
54  m_message(message),
55  m_reason(reason),
56  m_exceptionType(exceptionType),
57  m_exceptionMessage(exceptionMessage),
58  m_httpCode(httpCode)
59  {
60  };
61  std::string getSeverity() { return m_severity; };
62  std::string getMessage() { return m_message; };
63  std::string getReason() { return m_reason; };
64  std::string getExceptionType() { return m_exceptionType; };
65  std::string getExceptionMessage() { return m_exceptionMessage; };
66  int getHttpCode() { return m_httpCode; };
67  private:
68  std::string m_severity;
69  std::string m_message;
70  std::string m_reason;
71  std::string m_exceptionType;
72  std::string m_exceptionMessage;
73  int m_httpCode;
74  };
75  std::vector<Message> m_messages;
76  bool m_hasErrors;
77 };
78 #endif
bool hasMessages()
The error report contains at least one message.
Definition: omferror.h:42
An encapsulation of an error return from an OMF call.
Definition: omferror.h:21
void setFromHttpResponse(const std::string &json)
Parse error information from an OMF POST response JSON document.
Definition: OMFError.cpp:54
int getHttpCode()
Return the most severe HTTP Code from all messages.
Definition: OMFError.cpp:173
std::string getEventSeverity(unsigned int offset)
Get the event severity for a given message.
Definition: OMFError.cpp:228
std::string getEventReason(unsigned int offset)
Return the error reason for the given message.
Definition: OMFError.cpp:211
bool Log(const std::string &mainMessage, bool filterDuplicates=true)
Log all available messages.
Definition: OMFError.cpp:280
std::string getEventExceptionType(unsigned int offset)
Get the event exception type for a given message.
Definition: OMFError.cpp:245
std::string getEventExceptionMessage(unsigned int offset)
Get the event exception message for a given message.
Definition: OMFError.cpp:262
bool hasErrors()
The error report contains at least one error level event.
Definition: omferror.h:38
~OMFError()
Destructor for the error class.
Definition: OMFError.cpp:45
std::string getMessage(unsigned int offset)
Return the error message for the given message.
Definition: OMFError.cpp:194
OMFError()
Constructors.
Definition: OMFError.cpp:33