Class: GrapeTokenAuth::UnauthorizedMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/grape_token_auth/unauthorized_middleware.rb

Class Method Summary collapse

Class Method Details

.call(env) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/grape_token_auth/unauthorized_middleware.rb', line 4

def self.call(env)
  warden_opts = env.fetch('warden.options', {})
  errors = warden_opts['errors'] || warden_opts[:errors]
  [401,
   { 'Content-Type' => 'application/json'
   },
   prepare_errors(errors)
  ]
end

.prepare_errors(errors) ⇒ Object



14
15
16
17
18
19
# File 'lib/grape_token_auth/unauthorized_middleware.rb', line 14

def self.prepare_errors(errors)
  return [] unless errors
  return [errors.to_json] if errors.class == Hash
  return [{ 'errors' => errors }.to_json] if errors.class == String
  []
end