Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/expede/phoenix_exceptional
Exceptional error/exception helpers for Phoenix
https://github.com/expede/phoenix_exceptional
Last synced: about 1 month ago
JSON representation
Exceptional error/exception helpers for Phoenix
- Host: GitHub
- URL: https://github.com/expede/phoenix_exceptional
- Owner: expede
- Created: 2016-12-20T02:53:01.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2016-12-21T20:53:41.000Z (almost 8 years ago)
- Last Synced: 2024-05-01T14:59:26.623Z (7 months ago)
- Language: Elixir
- Homepage:
- Size: 10.7 KB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Phoenix/Exceptional
[Exceptional](https://hex.pm/packages/exceptional) error/exception helpers for [Phoenix](http://www.phoenixframework.org)
[![Build Status](https://travis-ci.org/expede/phoenix_exceptional.svg?branch=master)](https://travis-ci.org/expede/phoenix_exceptional) [![Inline docs](http://inch-ci.org/github/expede/phoenix_exceptional.svg?branch=master)](http://inch-ci.org/github/expede/phoenix_exceptional) [![Deps Status](https://beta.hexfaktor.org/badge/all/github/expede/phoenix_exceptional.svg)](https://beta.hexfaktor.org/github/expede/phoenix_exceptional) [![hex.pm version](https://img.shields.io/hexpm/v/phoenix_exceptional.svg?style=flat)](https://hex.pm/packages/phoenix_exceptional) [![API Docs](https://img.shields.io/badge/api-docs-yellow.svg?style=flat)](http://hexdocs.pm/phoenix_exceptional/) [![license](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)](https://github.com/expede/phoenix_exceptional/blob/master/LICENSE)
## Installation
Add `phoenix_exceptional` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[{:phoenix_exceptional, "~> 1.0"}]
end
```## Views
Automated rendering of error views based on the `message` field on exception structs.
This is often sufficient for simple JSON cases and pre-release HTML. It is recommended to write custom error views before production to give your users as much detail as possible in the user friendliest way that their content type allows.```elixir
# /web/views/error_view.exdefmodule AwesomeApp.ErrorView do
use Phoenix.Exceptionaldefrender :error, for: 401, do: "Not authorized"
defrender :error, for: 404, only: [:json], do: "Data not found"
defrender :error, for: 422, except: [:html] do: "Unprocessible entity"
defrender :error, for: 500, do: "Server internal error"
end
``````bash
# Example JSON Error Response404 %{error: "Data not found", reason: "Photo deleted"}
# Example HTML Error Response
500 "Server internal error"
```