Sha256: 809117c9116af5bcf96a343bb3aa667d08e63cd16cf3afc5d202275dd1fe9662

Contents?: true

Size: 1.67 KB

Versions: 21

Compression:

Stored size: 1.67 KB

Contents

Exceptions
===

Anything but a response code indicating success (2**) raises an exception.

```ruby

  LHC.get('localhost') # UnknownError: 0
  LHC.get('http://localhost:3000') # LHC::Timeout: 0

```

You can access the response object that was causing the error.

```ruby
LHC.get('local.ch')
rescue => e
  e.response #<LHC:Response>
  e.response.code # 403
  e.response.timeout? # false
  Rails.logger.error e
  # LHC::UnknownError: get http://local.cac
  # Params: {:url=>"http://local.cac", :method=>:get}
  # Response Code: 0
  # <Response Body>
```

All errors that are raise by LHC inherit from `LHC::Error`.
They are divided into `LHC::ClientError`, `LHC::ServerError`, `LHC::Timeout` and `LHC::UnkownError` and mapped according to the following status code.

```ruby
400 => LHC::BadRequest
401 => LHC::Unauthorized
402 => LHC::PaymentRequired
403 => LHC::Forbidden
403 => LHC::Forbidden
404 => LHC::NotFound
405 => LHC::MethodNotAllowed
406 => LHC::NotAcceptable
407 => LHC::ProxyAuthenticationRequired
408 => LHC::RequestTimeout
409 => LHC::Conflict
410 => LHC::Gone
411 => LHC::LengthRequired
412 => LHC::PreconditionFailed
413 => LHC::RequestEntityTooLarge
414 => LHC::RequestUriToLong
415 => LHC::UnsupportedMediaType
416 => LHC::RequestedRangeNotSatisfiable
417 => LHC::ExpectationFailed
422 => LHC::UnprocessableEntity
423 => LHC::Locked
424 => LHC::FailedDependency
426 => LHC::UpgradeRequired

500 => LHC::InternalServerError
501 => LHC::NotImplemented
502 => LHC::BadGateway
503 => LHC::ServiceUnavailable
504 => LHC::GatewayTimeout
505 => LHC::HttpVersionNotSupported
507 => LHC::InsufficientStorage
510 => LHC::NotExtended

timeout? => LHC::Timeout

anything_else => LHC::UnknownError
```

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
lhc-9.4.0 docs/exceptions.md
lhc-9.3.1 docs/exceptions.md
lhc-9.3.0 docs/exceptions.md
lhc-9.2.0 docs/exceptions.md
lhc-9.1.2 docs/exceptions.md
lhc-9.1.2.pre docs/exceptions.md
lhc-9.1.1 docs/exceptions.md
lhc-8.1.1 docs/exceptions.md
lhc-9.1.0 docs/exceptions.md
lhc-9.0.0 docs/exceptions.md
lhc-8.1.0 docs/exceptions.md
lhc-8.0.0 docs/exceptions.md
lhc-7.3.3 docs/exceptions.md
lhc-7.3.2 docs/exceptions.md
lhc-7.3.1 docs/exceptions.md
lhc-7.3.0 docs/exceptions.md
lhc-7.2.0 docs/exceptions.md
lhc-7.1.0 docs/exceptions.md
lhc-7.0.1 docs/exceptions.md
lhc-7.0.0 docs/exceptions.md