Stroika Library 3.0d25
 
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
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 */
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{});
58 ClientErrorException (Status status, const exception& 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_*/
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
ClientErrorException is to capture exceptions caused by a bad (e.g ill-formed) request.