This repository has been archived by the owner on Mar 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaperwork.ex
57 lines (46 loc) · 1.55 KB
/
paperwork.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
defmodule Paperwork do
import Plug
use Paperwork.Server
use Paperwork.Helpers.Response
defmacro __using__(_) do
quote do
before do
plug Plug.Logger
plug Corsica, origins: "*"
plug Plug.Parsers,
pass: ["*/*"],
json_decoder: Jason,
parsers: [:urlencoded, :json, :multipart]
end
resources do
get do
json(conn, %{library: :paperworkex})
end
end
rescue_from Unauthorized, as: e do
conn
|> resp({:unauthorized, %{status: 1, content: %{message: e.message}}})
end
rescue_from [MatchError, RuntimeError], as: e do
IO.inspect e
conn
|> resp({:error, %{status: 1, content: e}})
end
rescue_from Maru.Exceptions.InvalidFormat, as: e do
IO.inspect e
conn
|> resp({:badrequest, %{status: 1, content: %{param: e.param, reason: e.reason}}})
end
rescue_from Maru.Exceptions.NotFound, as: e do
IO.inspect e
conn
|> resp({:notfound, %{status: 1, content: %{method: e.method, route: e.path_info}}})
end
rescue_from :all, as: e do
IO.inspect e
conn
|> resp({:error, %{status: 1, content: e}})
end
end
end
end