Skip to content

Commit

Permalink
Add new kinds of errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mjacobus committed Aug 16, 2022
1 parent 60e706e commit b279dfc
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
29 changes: 29 additions & 0 deletions lib/koine/rest_client/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,38 @@ def initialize(response)
end
end

# 400
BadRequestError = Class.new(Error)
NotFoundError = Class.new(Error)
UnauthorizedError = Class.new(Error)
PaymentRequiredExperimentalError = Class.new(Error)
ForbiddenError = Class.new(Error)
MethodNotAllowedError = Class.new(Error)
NotAcceptableError = Class.new(Error)
ProxyAuthenticationRequiredError = Class.new(Error)
RequestTimeoutError = Class.new(Error)
ConflictError = Class.new(Error)
GoneError = Class.new(Error)
LengthRequiredError = Class.new(Error)
PreconditionFailedError = Class.new(Error)
PayloadTooLargeError = Class.new(Error)
URITooLongError = Class.new(Error)
UnsupportedMediaTypeError = Class.new(Error)
RangeNotSatisfiableError = Class.new(Error)
ExpectationFailedError = Class.new(Error)
ImATeapotError = Class.new(Error)

# 500
InternalServerError = Class.new(Error)
NotImplementedError = Class.new(Error)
BadGatewayError = Class.new(Error)
ServiceUnavailableError = Class.new(Error)
GatewayTimeoutError = Class.new(Error)
HTTPVersionNotSupportedError = Class.new(Error)
VariantAlsoNegotiatesError = Class.new(Error)
InsufficientStorageError = Class.new(Error)
LoopDetectedError = Class.new(Error)
NotExtendedError = Class.new(Error)
NetworkAuthenticationRequiredError = Class.new(Error)
end
end
28 changes: 27 additions & 1 deletion lib/koine/rest_client/response_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,34 @@ def error_for_code(code)
{
400 => BadRequestError,
401 => UnauthorizedError,
402 => PaymentRequiredExperimentalError,
403 => ForbiddenError,
404 => NotFoundError,
500 => InternalServerError
405 => MethodNotAllowedError,
406 => NotAcceptableError,
407 => ProxyAuthenticationRequiredError,
408 => RequestTimeoutError,
409 => ConflictError,
410 => GoneError,
411 => LengthRequiredError,
412 => PreconditionFailedError,
413 => PayloadTooLargeError,
414 => URITooLongError,
415 => UnsupportedMediaTypeError,
416 => RangeNotSatisfiableError,
417 => ExpectationFailedError,
418 => ImATeapotError,
500 => InternalServerError,
501 => NotImplementedError,
502 => BadGatewayError,
503 => ServiceUnavailableError,
504 => GatewayTimeoutError,
505 => HTTPVersionNotSupportedError,
506 => VariantAlsoNegotiatesError,
507 => InsufficientStorageError,
508 => LoopDetectedError,
510 => NotExtendedError,
511 => NetworkAuthenticationRequiredError
}.fetch(code) { Error }
end
end
Expand Down

0 comments on commit b279dfc

Please sign in to comment.