Stroika Library
3.0d16
Help-Home
Loading...
Searching...
No Matches
ClientErrorException.h
1
/*
2
* Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3
*/
4
#ifndef _Stroika_Foundation_IO_Network_HTTP_ClientErrorException_h_
5
#define _Stroika_Foundation_IO_Network_HTTP_ClientErrorException_h_ 1
6
7
#include "Stroika/Foundation/StroikaPreComp.h"
8
9
#include "Exception.h"
10
11
/**
12
*/
13
14
namespace
Stroika::Foundation::IO::Network::HTTP
{
15
16
using
Foundation::Characters::String;
17
18
/**
19
* \brief ClientErrorException is to capture exceptions caused by a bad (e.g ill-formed) request.
20
*
21
* This is typically what you want to throw (or translate to one of these) an exception in the webserver framework
22
* that should be treated as an error in the client request, and not a server failure (assignment of blame).
23
*
24
* TODO:
25
* @todo consider adding a 'based-on' field so that original exception gets copied around.
26
*
27
* @todo consider smarter mapping of basedOnInnerException to status codes - like TimeoutException to 408 Request Timeout
28
*/
29
class
ClientErrorException
:
public
Exception
{
30
private
:
31
using
inherited
=
Exception
;
32
33
public
:
34
/*
35
* If no reason is given, a default is generated based on the status code, or other arguments.
36
*
37
* If given an 'inner exception' to be based on, this takes that exception to form a message, and automatically
38
* generates a status (unless provided explicitly).
39
*
40
* \par Example Usage
41
* \code
42
* Throw (ClientErrorException{StatusCodes::kUnauthorized});
43
* \endcode
44
*
45
* \par Example Usage
46
* \code
47
* Throw (ClientErrorException{StatusCodes::kBadRequest});
48
* \endcode
49
*
50
* \pre 400 <= status and status < 500
51
*/
52
ClientErrorException
(
Status
status = StatusCodes::kBadRequest,
const
String
& reason =
String
{});
53
ClientErrorException
(
const
String
& reason);
54
ClientErrorException
(
const
Exception
& basedOnInnerException);
55
ClientErrorException
(
Status
status,
const
Exception
& basedOnInnerException);
56
ClientErrorException
(
const
exception& basedOnInnerException);
57
ClientErrorException
(
Status
status,
const
exception& basedOnInnerException);
58
ClientErrorException
(
const
exception_ptr& basedOnInnerException);
59
ClientErrorException
(
Status
status,
const
exception_ptr& basedOnInnerException);
60
61
/**
62
* Utility to map any functions thrown in the given (typically lambda) into a ClientErrorException
63
*/
64
template
<invocable FUNCTION,
typename
RESULT_TYPE = std::invoke_result_t<FUNCTION>>
65
static
RESULT_TYPE
TreatExceptionsAsClientError
(FUNCTION&& f);
66
};
67
68
}
69
70
/*
71
********************************************************************************
72
***************************** Implementation Details ***************************
73
********************************************************************************
74
*/
75
#include "ClientErrorException.inl"
76
77
#endif
/*_Stroika_Foundation_IO_Network_HTTP_ClientErrorException_h_*/
Stroika::Foundation::Characters::String
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition
String.h:201
Stroika::Foundation::IO::Network::HTTP::ClientErrorException
ClientErrorException is to capture exceptions caused by a bad (e.g ill-formed) request.
Definition
ClientErrorException.h:29
Stroika::Foundation::IO::Network::HTTP::ClientErrorException::TreatExceptionsAsClientError
static RESULT_TYPE TreatExceptionsAsClientError(FUNCTION &&f)
Definition
ClientErrorException.inl:25
Stroika::Foundation::IO::Network::HTTP::Exception
Definition
IO/Network/HTTP/Exception.h:26
Stroika::Foundation::IO::Network::HTTP
Definition
CacheControl.h:17
Stroika::Foundation::IO::Network::HTTP::Status
unsigned int Status
Definition
Status.h:17
Library
Sources
Stroika
Foundation
IO
Network
HTTP
ClientErrorException.h
Generated by
1.9.8