Save REPP log after every request

This commit is contained in:
Karl Erik Õunapuu 2020-10-14 16:04:27 +03:00
parent 9b8d74fe30
commit 6d96a09b5c
No known key found for this signature in database
GPG key ID: C9DD647298A34764
2 changed files with 12 additions and 3 deletions

View file

@ -4,13 +4,22 @@ module Repp
rescue_from ActiveRecord::RecordNotFound, with: :not_found_error
before_action :authenticate_user
before_action :check_ip_restriction
attr_reader :current_user
rescue_from ActionController::ParameterMissing do |exception|
render json: { code: 2003, message: exception }, status: :bad_request
end
after_action do
ApiLog::ReppLog.create(
{ request_path: request.path, request_method: request.request_method,
request_params: request.params.except('route_info').to_json, uuid: request.try(:uuid),
response: @response.to_json, response_code: status, ip: request.ip,
api_user_name: current_user.try(:username),
api_user_registrar: current_user.try(:registrar).try(:to_s) }
)
end
private
def render_success(code: nil, message: nil, data: nil)