https://mooseframework.inl.gov
Public Member Functions | Protected Member Functions | 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. More...
 

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 }
void setError(const std::string &error)
Set the error message.
Represents a response to the client from the server.

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.

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
inherited
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
inlineinherited
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
inlineinherited
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
inlineinherited
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)
inlineprotectedinherited

Set the error message.

Definition at line 166 of file WebServerControl.h.

Referenced by ErrorResponse().

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

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