Skip to content

Commit

Permalink
Merge pull request #15012 from eduardoj/fix/improve_error_message_tok…
Browse files Browse the repository at this point in the history
…en_not_found

Improve error message for token not found
  • Loading branch information
saraycp committed Oct 6, 2023
2 parents b92d06f + 4551624 commit 283d3a5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/api/app/controllers/person/token_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require 'xmlhash'
module Person
class TokenController < ApplicationController
rescue_from ActiveRecord::RecordNotFound, with: :record_not_found

before_action :set_user

# GET /person/<login>/token
Expand Down Expand Up @@ -28,16 +30,16 @@ def create
def delete
authorize @user, :update?

token = @user.tokens.find(params[:id])

render_error status: 404 && return unless token

token.destroy
@user.tokens.find(params[:id]).destroy
render_ok
end

private

def record_not_found(exception)
render_error status: 404, message: "Couldn't find Token with 'id'=#{exception.id}"
end

def set_user
@user = User.find_by(login: params[:login]) || User.find_nobody!
end
Expand Down
2 changes: 1 addition & 1 deletion src/api/public/apidocs/paths/person_login_token_id.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ delete:
$ref: '../components/schemas/api_response.yaml'
example:
code: not_found
summary: "Couldn't find Token with 'id'=33 [WHERE `tokens`.`user_id` = ?]"
summary: Couldn't find Token with 'id'=33
tags:
- Person

0 comments on commit 283d3a5

Please sign in to comment.