ApiException
This gem is a compilation of common errors that can be encountered with File, Model and Controller handling
Usage
# This is the base class
# New exception handlers should inherit from this class
ApiException::BaseException
# You can initialize with the following params
# error_type -> This argument should be a symbol
# errors -> This argument should be an array of string errors
# params -> Should be a hash as params for I18n.t translations (optional)
# platform -> Should specify where this error is rendered from, 'API' value is by default (optional)
ApiException::BaseException.new(:UNKNOWN_ERROR, ["Something went wrong"], { process: "" })
Examples availables
ApiException::ModelException.new(:RECORD_NOT_FOUND, ["Item not found"], { model: "User"})
#=> Record not found for User (ApiException::ModelException)
ApiException::ControllerException.new(:INVALID_PARAMS, ["cant parse body params"])
#=> The provided params are invalid (ApiException::ControllerException)
ApiException::FileException.new(:UNSUPPORTED_FILE, ["wrong file extension"])
#=> The file you are trying to upload is not supported (ApiException::FileException)
ApiException::RequestException.new(:TIMEOUT, ["Server response time exceed"], { timeout: "3 mins"})
#=> The response timeout was exceeded: 3 mins (ApiException::RequestException)
ApiException::UserException.new(:DUPLICATED_USER, ["user data already exist"])
#=> Duplicate user (ApiException::UserException)
Installation
Add this line to your application's Gemfile:
gem "api_exception"
And then execute:
$ bundle
Or install it yourself as:
$ gem install api_exception
Contributing
Contribution directions go here.
License
The gem is available as open source under the terms of the MIT License.