README.md in errawr-1.1.6 vs README.md in errawr-1.2.0

- old
+ new

@@ -18,87 +18,49 @@ $ gem install errawr ## Usage -### Localizations +### Defining and Raising Errors -Errawr uses [I18n](https://github.com/svenfuchs/i18n) for easily managing error localizations. Just define a locale using the ```errawr``` key. +Errawr uses [I18n](https://github.com/svenfuchs/i18n) for easily managing error +localizations. Just define an error in a locale file. Make sure to use the +```errawr``` key. ```yaml en: errawr: - your_error: Your error message here + your_error: + message: My awesome error message + metadata: + http_status: 400 ``` -Need to add more locale files? Use I18n's standard ```load_path```. +Then just raise your exception using the `#error!` method. ```ruby -I18n.load_path += Dir.glob('lib/your_lib/locales/*.{rb,yml}') -``` - -### Registering Errors - -Before you can raise an error you'll need to register it first. - -```ruby -Errawr.register!(:your_error) -``` - -### Raising Errors - -```ruby begin Errawr.error!(:your_error) rescue => e - puts e.message # Localized error message defined in locale file -end -``` - -### Metadata - -It's possible to add additional information to a registered error through metadata. Just specify a ```metadata``` hash when either registering: - -```ruby -Errawr.register!(:your_error, metadata: { http_status: 400 }) -begin - Errawr.error!(:your_error) -rescue => e puts e.metadata[:http_status] # Will return 400 end ``` -or throwing an error: +Need to add more locale files? Use I18n's standard ```load_path```. ```ruby -Errawr.register!(:your_error) -begin - Errawr.error!(:your_error, metadata: { http_status: 400 }) -rescue => e - puts e.metadata[:http_status] # Will return 400 -end +I18n.load_path += Dir.glob('lib/your_lib/locales/*.{rb,yml}') ``` -### Managing Errors through Locale Files +### Metadata -It's also possible to manage your errors and their metadata purely through locale files. +It's possible to add additional information to a registered error through +metadata. Just specify a ```metadata``` hash when throwing an error: -```yaml -en: - errawr: - your_error: - message: My awesome error message - metadata: - http_status: 400 -``` - -Then just register and raise your exceptions like normal. - ```ruby -Errawr.register!(:your_error) begin - Errawr.error!(:your_error) + Errawr.error!(:your_error, metadata: { http_status: 400 }) rescue => e puts e.metadata[:http_status] # Will return 400 end ``` @@ -112,21 +74,21 @@ your_error: message: "My awesome error message is: %{error_message}" ``` ```ruby -Errawr.register!(:your_error, error_message: 'You did it wrong!') begin - Errawr.error!(:your_error) + Errawr.error!(:your_error, error_message: 'You did it wrong!') rescue => e puts e.message # Will return "My awesome error message is: You did it wrong!" end ``` ### Overrides -Want to override that metadata you registered? That's cool too. +It's possible to override metadata stored in a locale file both globally and +on a per use basis. ```yaml en: errawr: your_error: @@ -155,11 +117,11 @@ Errawr.error!(:your_error, message: 'Yet another error message', metadata: { http_status: 404 }) rescue => e puts e.message # => Will return "Yet another error message" puts e.metadata[:http_status] # => Will return 404 end -``` +``` ### Custom Error Classes Want to write a custom error class? No problem! @@ -192,6 +154,6 @@ ## Credits [![Sticksnleaves](http://sticksnleaves-wordpress.herokuapp.com/wp-content/themes/sticksnleaves/images/snl-logo-116x116.png)](http://www.sticksnleaves.com) Errawr is maintained and funded by [Sticksnleaves](http://www.sticksnleaves.com) -Thanks to all of our [contributors](https://github.com/anthonator/errawr/graphs/contributors) \ No newline at end of file +Thanks to all of our [contributors](https://github.com/anthonator/errawr/graphs/contributors)