Skip to content
Download

UnauthorizedException

mach::UnauthorizedException

Represents an HTTP 401 (Unauthorized) exception.

UnauthorizedException indicates that a request requires authentication or that the provided authentication credentials are invalid. It is typically thrown when a client attempts to access a protected resource without successfully authenticating.

UnauthorizedException derives from HttpException.

Primary header:

#include <mach/exceptions/UnauthorizedException.hpp>

Convenience header:

#include <mach/exceptions.hpp>
class UnauthorizedException final : public HttpException {
public:
explicit UnauthorizedException(
std::string message = "Authentication is required to access this resource."
);
};
Property Value
Code 401
Status Unauthorized

UnauthorizedException inherits the public member functions of HttpException.

The exception message defaults to "Authentication is required to access this resource." when no message is provided.

throw mach::UnauthorizedException();
Name Description
HttpException Base class for Mach HTTP exceptions.
BadRequestException Represents an HTTP 400 Bad Request.
ForbiddenException Represents an HTTP 403 Forbidden.
NotFoundException Represents an HTTP 404 Not Found.
ConflictException Represents an HTTP 409 Conflict.