Stroika Library 3.0d16
 
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
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 */
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_*/
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.