https://mooseframework.inl.gov
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
WebServerControl::Response Struct Reference

Represents a response to the client from the server. More...

#include <WebServerControl.h>

Inheritance diagram for WebServerControl::Response:
[legend]

Public Member Functions

 Response ()=default
 
 Response (const unsigned int status_code)
 Construct a response given a status code. More...
 
 Response (const unsigned int status_code, const nlohmann::json &json)
 Construct a response given a status code and JSON data. More...
 
unsigned int getStatusCode () const
 
bool hasJSON () const
 
const nlohmann::json & getJSON () const
 
bool hasError () const
 
const std::string & getError () const
 

Protected Member Functions

void setError (const std::string &error)
 Set the error message. More...
 

Private Attributes

unsigned int _status_code = 0
 The status code. More...
 
std::optional< nlohmann::json > _json
 The JSON data, if any. More...
 
std::optional< std::string > _error
 The error message, if any. More...
 

Detailed Description

Represents a response to the client from the server.

Definition at line 126 of file WebServerControl.h.

Constructor & Destructor Documentation

◆ Response() [1/3]

WebServerControl::Response::Response ( )
default

◆ Response() [2/3]

WebServerControl::Response::Response ( const unsigned int  status_code)

Construct a response given a status code.

Definition at line 827 of file WebServerControl.C.

827 : _status_code(status_code) {}
unsigned int _status_code
The status code.

◆ Response() [3/3]

WebServerControl::Response::Response ( const unsigned int  status_code,
const nlohmann::json &  json 
)

Construct a response given a status code and JSON data.

Definition at line 829 of file WebServerControl.C.

830  : _status_code(status_code), _json(json)
831 {
832 }
std::optional< nlohmann::json > _json
The JSON data, if any.
unsigned int _status_code
The status code.

Member Function Documentation

◆ getError()

const std::string & WebServerControl::Response::getError ( ) const
Returns
Get the error message if it exists

Definition at line 843 of file WebServerControl.C.

Referenced by WebServerControl::addServerAction().

844 {
845  if (!_error)
846  ::mooseError("Does not have an error");
847  return *_error;
848 }
std::optional< std::string > _error
The error message, if any.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:271

◆ getJSON()

const nlohmann::json & WebServerControl::Response::getJSON ( ) const
Returns
Get the JSON data in the response if it exists

Definition at line 835 of file WebServerControl.C.

Referenced by WebServerControl::addServerAction().

836 {
837  if (!_json)
838  throw std::runtime_error("Response does not contain JSON when it should");
839  return *_json;
840 }
std::optional< nlohmann::json > _json
The JSON data, if any.

◆ getStatusCode()

unsigned int WebServerControl::Response::getStatusCode ( ) const
inline
Returns
The status code for the response

Definition at line 142 of file WebServerControl.h.

Referenced by WebServerControl::addServerAction().

142 { return _status_code; }
unsigned int _status_code
The status code.

◆ hasError()

bool WebServerControl::Response::hasError ( ) const
inline
Returns
Whether or not the response is an error

Definition at line 156 of file WebServerControl.h.

Referenced by WebServerControl::addServerAction().

156 { return _error.has_value(); }
std::optional< std::string > _error
The error message, if any.

◆ hasJSON()

bool WebServerControl::Response::hasJSON ( ) const
inline
Returns
Whether or not the response has JSON data

Definition at line 147 of file WebServerControl.h.

Referenced by WebServerControl::addServerAction().

147 { return _json.has_value(); }
std::optional< nlohmann::json > _json
The JSON data, if any.

◆ setError()

void WebServerControl::Response::setError ( const std::string &  error)
inlineprotected

Set the error message.

Definition at line 166 of file WebServerControl.h.

Referenced by WebServerControl::ErrorResponse::ErrorResponse().

166 { _error = error; }
std::optional< std::string > _error
The error message, if any.

Member Data Documentation

◆ _error

std::optional<std::string> WebServerControl::Response::_error
private

The error message, if any.

Definition at line 174 of file WebServerControl.h.

Referenced by hasError(), and setError().

◆ _json

std::optional<nlohmann::json> WebServerControl::Response::_json
private

The JSON data, if any.

Definition at line 172 of file WebServerControl.h.

Referenced by hasJSON().

◆ _status_code

unsigned int WebServerControl::Response::_status_code = 0
private

The status code.

Definition at line 170 of file WebServerControl.h.

Referenced by getStatusCode().


The documentation for this struct was generated from the following files: