https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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.
 
 Response (const unsigned int status_code, const nlohmann::json &json)
 Construct a response given a status code and JSON data.
 
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.
 

Private Attributes

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

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.

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.

844{
845 if (!_error)
846 ::mooseError("Does not have an error");
847 return *_error;
848}
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
std::optional< std::string > _error
The error message, if any.

Referenced by WebServerControl::addServerAction().

◆ 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.

836{
837 if (!_json)
838 throw std::runtime_error("Response does not contain JSON when it should");
839 return *_json;
840}

Referenced by WebServerControl::addServerAction().

◆ getStatusCode()

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

Definition at line 142 of file WebServerControl.h.

142{ return _status_code; }

Referenced by WebServerControl::addServerAction().

◆ hasError()

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

Definition at line 156 of file WebServerControl.h.

156{ return _error.has_value(); }

Referenced by WebServerControl::addServerAction().

◆ hasJSON()

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

Definition at line 147 of file WebServerControl.h.

147{ return _json.has_value(); }

Referenced by WebServerControl::addServerAction().

◆ setError()

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

Set the error message.

Definition at line 166 of file WebServerControl.h.

166{ _error = error; }

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

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: