Stroika Library
3.0d25
Help-Home
Loading...
Searching...
No Matches
ClientErrorException.h
1
/*
2
* Copyright(c) Sophist Solutions, Inc. 1990-2026. 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 "Stroika/Foundation/IO/Network/HTTP/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 a timeout
28
* (code () == errc::timed_out) to 408 Request Timeout
29
*/
30
class
ClientErrorException
:
public
Exception
{
31
private
:
32
using
inherited
=
Exception
;
33
34
public
:
35
/*
36
* If no reason is given, a default is generated based on the status code, or other arguments.
37
*
38
* If given an 'inner exception' to be based on, this takes that exception to form a message, and automatically
39
* generates a status (unless provided explicitly).
40
*
41
* \par Example Usage
42
* \code
43
* Throw (ClientErrorException{StatusCodes::kUnauthorized});
44
* \endcode
45
*
46
* \par Example Usage
47
* \code
48
* Throw (ClientErrorException{StatusCodes::kBadRequest});
49
* \endcode
50
*
51
* \pre 400 <= status and status < 500
52
*/
53
ClientErrorException
(
Status
status = StatusCodes::kBadRequest,
const
String
&
reason
=
String
{});
54
ClientErrorException
(
const
String
&
reason
);
55
ClientErrorException
(
const
Exception
&
basedOnInnerException
);
56
ClientErrorException
(
Status
status,
const
Exception
&
basedOnInnerException
);
57
ClientErrorException
(
const
exception&
basedOnInnerException
);
58
ClientErrorException
(
Status
status,
const
exception&
basedOnInnerException
);
59
ClientErrorException
(
const
exception_ptr
&
basedOnInnerException
);
60
ClientErrorException
(
Status
status,
const
exception_ptr
&
basedOnInnerException
);
61
62
/**
63
* Utility to map any functions thrown in the given (typically lambda) into a ClientErrorException
64
*/
65
template
<invocable FUNCTION,
typename
RESULT_TYPE = std::invoke_result_t<FUNCTION>>
66
static
RESULT_TYPE
TreatExceptionsAsClientError
(FUNCTION&& f);
67
};
68
69
}
70
71
/*
72
********************************************************************************
73
***************************** Implementation Details ***************************
74
********************************************************************************
75
*/
76
#include "ClientErrorException.inl"
77
78
#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::Execution::ExceptionStringHelper::As
nonvirtual T As() const
Stroika::Foundation::IO::Network::HTTP::ClientErrorException
ClientErrorException is to capture exceptions caused by a bad (e.g ill-formed) request.
Definition
ClientErrorException.h:30
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