Commit 98a863b7fbbe78340f4d2b99bdacc2af78ba4460

Authored by Spencer Alan
1 parent d20a646a
Exists in master

• add exception handler

app/controllers/concerns/scim_rails/exception_handler.rb
@@ -8,6 +8,9 @@ module ScimRails @@ -8,6 +8,9 @@ module ScimRails
8 class InvalidCredentials < StandardError 8 class InvalidCredentials < StandardError
9 end 9 end
10 10
  11 + class InvalidQuery < StandardError
  12 + end
  13 +
11 included do 14 included do
12 rescue_from ScimRails::ExceptionHandler::InvalidCredentials do 15 rescue_from ScimRails::ExceptionHandler::InvalidCredentials do
13 json_response( 16 json_response(
@@ -20,14 +23,15 @@ module ScimRails @@ -20,14 +23,15 @@ module ScimRails
20 ) 23 )
21 end 24 end
22 25
23 - rescue_from ScimRails::ExceptionHandler::MissingCredentials do 26 + rescue_from ScimRails::ExceptionHandler::InvalidQuery do
24 json_response( 27 json_response(
25 { 28 {
26 schemas: ["urn:ietf:params:scim:api:messages:2.0:Error"], 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 end 36 end
33 37
@@ -43,15 +47,26 @@ module ScimRails @@ -43,15 +47,26 @@ module ScimRails
43 end 47 end
44 48
45 rescue_from ActiveRecord::RecordInvalid do |e| 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 end 70 end
56 end 71 end
57 end 72 end