Commit d92a53537b22b9246241d1e1a1e3bd23405df357

Authored by Spencer Alan
1 parent 5e2186a6
Exists in master

update to scim compliant errors

app/controllers/concerns/scim_rails/exception_handler.rb
... ... @@ -10,19 +10,48 @@ module ScimRails
10 10  
11 11 included do
12 12 rescue_from ScimRails::ExceptionHandler::InvalidCredentials do
13   - json_response({ message: "Invalid credentials" }, :unauthorized)
  13 + json_response(
  14 + {
  15 + schemas: ["urn:ietf:params:scim:api:messages:2.0:Error"],
  16 + detail: "Authorization failure. The authorization header is invalid or missing.",
  17 + status: "401"
  18 + },
  19 + :unauthorized
  20 + )
14 21 end
15 22  
16 23 rescue_from ScimRails::ExceptionHandler::MissingCredentials do
17   - json_response({ message: "Missing credentials" }, :unauthorized)
  24 + json_response(
  25 + {
  26 + schemas: ["urn:ietf:params:scim:api:messages:2.0:Error"],
  27 + detail: "Authorization failure. The authorization header is invalid or missing.",
  28 + status: "401"
  29 + },
  30 + :unauthorized
  31 + )
18 32 end
19 33  
20 34 rescue_from ActiveRecord::RecordNotFound do |e|
21   - json_response({ message: e.message }, :not_found)
  35 + json_response(
  36 + {
  37 + schemas: ["urn:ietf:params:scim:api:messages:2.0:Error"],
  38 + detail: "Resource #{e.id} not found.",
  39 + status: "404"
  40 + },
  41 + :not_found
  42 + )
22 43 end
23 44  
24 45 rescue_from ActiveRecord::RecordInvalid do |e|
25   - json_response({ message: e.message }, :unprocessable_entity)
  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 + )
26 55 end
27 56 end
28 57 end
... ...