https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
WebServerControl::ErrorResponse Struct Reference

Represents an error response to the client from the server. More...

#include <WebServerControl.h>

Inheritance diagram for WebServerControl::ErrorResponse:
[legend]

Public Member Functions

 ErrorResponse (const std::string &error, const unsigned int status_code=400)
 
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 an error response to the client from the server.

Definition at line 180 of file WebServerControl.h.

Constructor & Destructor Documentation

◆ ErrorResponse()

WebServerControl::ErrorResponse::ErrorResponse ( const std::string &  error,
const unsigned int  status_code = 400 
)

Definition at line 850 of file WebServerControl.C.

852 : WebServerControl::Response(status_code)
853{
854 setError(error);
855}
Represents a response to the client from the server.
void setError(const std::string &error)
Set the error message.

Member Function Documentation

◆ getError()

const std::string & WebServerControl::Response::getError ( ) const
inherited
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
inherited
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}
std::optional< nlohmann::json > _json
The JSON data, if any.

Referenced by WebServerControl::addServerAction().

◆ getStatusCode()

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

Definition at line 142 of file WebServerControl.h.

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

Referenced by WebServerControl::addServerAction().

◆ hasError()

bool WebServerControl::Response::hasError ( ) const
inlineinherited
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
inlineinherited
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)
inlineprotectedinherited

Set the error message.

Definition at line 166 of file WebServerControl.h.

166{ _error = error; }

Referenced by ErrorResponse().

Member Data Documentation

◆ _error

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

The error message, if any.

Definition at line 174 of file WebServerControl.h.

Referenced by WebServerControl::Response::hasError(), and WebServerControl::Response::setError().

◆ _json

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

The JSON data, if any.

Definition at line 172 of file WebServerControl.h.

Referenced by WebServerControl::Response::hasJSON().

◆ _status_code

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

The status code.

Definition at line 170 of file WebServerControl.h.

Referenced by WebServerControl::Response::getStatusCode().


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