NAME

Gears::X::HTTP - HTTP exception class

SYNOPSIS

use Gears::X::HTTP;

# Raise an HTTP error
Gears::X::HTTP->raise(404, "Page not found");
Gears::X::HTTP->raise(500, "Internal error");

# Create and raise later
my $error = Gears::X::HTTP->new(
	code => 403,
	message => "Access denied",
);
$error->raise;

# Catch and inspect
try {
	Gears::X::HTTP->raise(400, "Bad request");
}
catch ($e) {
	say $e->code;     # 400
	say $e->message;  # Bad request
	say $e;           # An error occured: [HTTP] 400 - Bad request (raised at ...)
}

DESCRIPTION

Gears::X::HTTP is an exception class for HTTP-related errors. It extends Gears::X with an HTTP status code attribute and provides a convenient interface for raising HTTP errors with appropriate codes.

The exception enforces that the status code is in the valid HTTP error range (400-500). The message is automatically formatted to include the status code.

INTERFACE

Attributes

code

The HTTP status code. Must be in the range 400-500 (inclusive). This covers client errors (4xx) and server errors (5xx).

Required in constructor

Methods

new

$object = $class->new(%args)

A standard Mooish constructor. Consult "Attributes" section to learn what keys can key passed in %args.

raise

$exception->raise()
$class->raise($code, $message)

Raises an HTTP exception. Same as "raise" in Gears::X, but adds an additional argument $code (for "code").

SEE ALSO

Gears::X - Base exception class