Sha256: e9b5d8e77970c4c73a8a0eb472b5138e485909d36a61f6b14dea83b3901c933e
Contents?: true
Size: 881 Bytes
Versions: 2
Compression:
Stored size: 881 Bytes
Contents
module Jobshop module AuthorizationHandler extend ActiveSupport::Concern class TokenMissing < StandardError; end class TokenInvalid < StandardError; end included do before_action :authorize_request rescue_from Jobshop::AuthorizationHandler::TokenMissing, with: :four_twenty_two rescue_from Jobshop::AuthorizationHandler::TokenInvalid, with: :four_twenty_two rescue_from ActiveRecord::RecordInvalid, with: :four_twenty_two rescue_from ActiveRecord::RecordNotFound do |e| render({ json: { message: e.message } }, :not_found) end attr_reader :current_user end private def four_twenty_two(e) render({ json: { message: e.message } }, :unprocessable_entity) end private def authorize_request @current_user = (AuthorizationService.new(request.headers).perform)[:user] end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
jobshop-0.0.163 | app/controllers/concerns/jobshop/authorization_handler.rb |
jobshop-0.0.157 | app/controllers/concerns/jobshop/authorization_handler.rb |