Commit 98a863b7fbbe78340f4d2b99bdacc2af78ba4460
1 parent
d20a646a
Exists in
master
• add exception handler
Showing
1 changed file
with
28 additions
and
13 deletions
Show diff stats
app/controllers/concerns/scim_rails/exception_handler.rb
... | ... | @@ -8,6 +8,9 @@ module ScimRails |
8 | 8 | class InvalidCredentials < StandardError |
9 | 9 | end |
10 | 10 | |
11 | + class InvalidQuery < StandardError | |
12 | + end | |
13 | + | |
11 | 14 | included do |
12 | 15 | rescue_from ScimRails::ExceptionHandler::InvalidCredentials do |
13 | 16 | json_response( |
... | ... | @@ -20,14 +23,15 @@ module ScimRails |
20 | 23 | ) |
21 | 24 | end |
22 | 25 | |
23 | - rescue_from ScimRails::ExceptionHandler::MissingCredentials do | |
26 | + rescue_from ScimRails::ExceptionHandler::InvalidQuery do | |
24 | 27 | json_response( |
25 | 28 | { |
26 | 29 | schemas: ["urn:ietf:params:scim:api:messages:2.0:Error"], |
27 | - detail: "Authorization failure. The authorization header is invalid or missing.", | |
28 | - status: "401" | |
30 | + scimType: "invalidFilter", | |
31 | + detail: "The specified filter syntax was invalid, or the specified attribute and filter comparison combination is not supported.", | |
32 | + status: "400" | |
29 | 33 | }, |
30 | - :unauthorized | |
34 | + :bad_request | |
31 | 35 | ) |
32 | 36 | end |
33 | 37 | |
... | ... | @@ -43,15 +47,26 @@ module ScimRails |
43 | 47 | end |
44 | 48 | |
45 | 49 | rescue_from ActiveRecord::RecordInvalid do |e| |
46 | - json_response( | |
47 | - { | |
48 | - schemas: ["urn:ietf:params:scim:api:messages:2.0:Error"], | |
49 | - scimType: "invalidValue", | |
50 | - detail: e.message, | |
51 | - status: "400" | |
52 | - }, | |
53 | - :unprocessable_entity | |
54 | - ) | |
50 | + case e.message | |
51 | + when /has already been taken/ | |
52 | + json_response( | |
53 | + { | |
54 | + schemas: ["urn:ietf:params:scim:api:messages:2.0:Error"], | |
55 | + detail: e.message, | |
56 | + status: "409" | |
57 | + }, | |
58 | + :conflict | |
59 | + ) | |
60 | + else | |
61 | + json_response( | |
62 | + { | |
63 | + schemas: ["urn:ietf:params:scim:api:messages:2.0:Error"], | |
64 | + detail: e.message, | |
65 | + status: "422" | |
66 | + }, | |
67 | + :unprocessable_entity | |
68 | + ) | |
69 | + end | |
55 | 70 | end |
56 | 71 | end |
57 | 72 | end | ... | ... |