Notice: The website is currently being udpated. Sorry for any inconvenience.
Exceptions
The most up-to-date list of HTTP status codes that Halcyon supports can be seen
at the GitHub source page
which is transformed into actual exception classes from the error message.
Here is a list of the actual Exception classes as created by this list and a
brief overview of when to use these exceptions:
100 Continue101 SwitchingProtocols102 Processing200 OK— this is the standard response, alias methodok201 Created— can be used to indicated success forcreateaction202 Accepted203 NonAuthoritativeInformation204 NoContent205 ResetContent206 PartialContent207 MultiStatus300 MultipleChoices301 MovedPermanently302 MovedTemporarily303 SeeOther304 NotModified305 UseProxy307 TemporaryRedirect400 BadRequest— can be used to indicate insufficient params, etc401 Unauthorized— can indicate authorization necessary402 PaymentRequired403 Forbidden404 NotFound— can indicate resources not found405 MethodNotAllowed406 NotAcceptable— can be used to indicate method is restricted to certain clients et al407 ProxyAuthenticationRequired408 RequestTimeout409 Conflict410 Gone411 LengthRequired412 PreconditionFailed413 RequestEntityTooLarge414 RequestURITooLarge415 UnsupportedMediaType416 RequestedRangeNotSatisfiable417 ExpectationFailed422 UnprocessableEntity— can be used to indicate models fail validations423 Locked424 FailedDependency425 NoCode426 UpgradeRequired— can be used to indicate change of API versions, etc500 InternalServerError— indicates uncaught error501 NotImplemented— can indicate non-functionality or partial implementation502 BadGateway503 ServiceUnavailable— can indicate the service is temporarily unavailable for maintenance504 GatewayTimeout505 HTTPVersionnotsupported506 VariantAlsoNegotiates507 InsufficientStorage510 NotExtended
Making Your Own
Although the standard exceptions available should be sufficient (they are
the HTTP response codes), you could certainly make up your own HTTP response
codes. Putting this inside of an init file or in the lib directory should
be fine:
1 ## lib/custom_exception.rb 2 ## or config/init/custom_exception.rb 3 class CustomException < Halcyon::Exceptions::Base 4 5 def initialize(body = 'Custom Exception') 6 super(460, body) 7 end 8 9 end
As you can see, the status code is the first argument to the base initialize
method and the body variable is set to the default error text. Obviously, the
exception name, file name, and error status should be more descriptive.
Pick a sane error code as well, something that hasn’t been used officially.
If at all possible, use the default response codes/exceptions.