Commit eb9cddbe authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Return correct error messages / http statuses for the public API

parent 7078ab9e
......@@ -6,7 +6,7 @@ module IssueLinks
def execute
if referenced_issues.blank?
return error('No Issue found for given params', 401)
return error('No Issue found for given params', 404)
end
create_issue_links
......
......@@ -8,7 +8,7 @@ module IssueLinks
end
def execute
return error('Unauthorized', 401) unless permission_to_remove_relation?
return error('No Issue Link found', 404) unless permission_to_remove_relation?
remove_relation
create_notes
......
......@@ -31,7 +31,6 @@ module API
end
post ':id/issues/:issue_iid/links' do
source_issue = find_project_issue(params[:issue_iid])
target_issue = find_project_issue(declared_params[:target_issue_iid],
declared_params[:target_project_id])
......@@ -46,7 +45,7 @@ module API
present issue_link, with: Entities::IssueLink
else
not_found!
render_api_error!(result[:message], result[:http_status])
end
end
......@@ -59,6 +58,9 @@ module API
delete ':id/issues/:issue_iid/links/:issue_link_id' do
issue_link = IssueLink.find(declared_params[:issue_link_id])
find_project_issue(params[:issue_iid])
find_project_issue(issue_link.target.iid.to_s, issue_link.target.project_id.to_s)
result = ::IssueLinks::DestroyService
.new(issue_link, current_user)
.execute
......@@ -66,7 +68,7 @@ module API
if result[:status] == :success
present issue_link, with: Entities::IssueLink
else
not_found!
render_api_error!(result[:message], result[:http_status])
end
end
end
......
......@@ -80,7 +80,7 @@ describe API::IssueLinks do
target_project_id: unauthorized_project.id, target_issue_iid: target_issue.iid
expect(response).to have_http_status(404)
expect(json_response['message']).to eq('404 Not Found')
expect(json_response['message']).to eq('No Issue found for given params')
end
end
......@@ -158,7 +158,7 @@ describe API::IssueLinks do
delete api("/projects/#{project.id}/issues/#{issue.iid}/links/#{issue_link.id}", user)
expect(response).to have_http_status(404)
expect(json_response['message']).to eq('404 Not Found')
expect(json_response['message']).to eq('No Issue Link found')
end
end
......@@ -180,7 +180,7 @@ describe API::IssueLinks do
delete api("/projects/#{project.id}/issues/#{issue.iid}/links/#{issue_link.id}", user)
expect(response).to have_http_status(404)
expect(json_response['message']).to eq('404 Not Found')
expect(json_response['message']).to eq('404 Project Not Found')
end
end
......
......@@ -73,7 +73,7 @@ describe Projects::IssueLinksController do
list_service_response = IssueLinks::ListService.new(issue, user).execute
expect(response).to have_http_status(401)
expect(response).to have_http_status(404)
expect(json_response).to eq('message' => 'No Issue found for given params', 'issues' => list_service_response.as_json)
end
end
......@@ -105,10 +105,10 @@ describe Projects::IssueLinksController do
let(:referenced_issue) { create :issue }
let(:user_role) { :developer }
it 'returns 401' do
it 'returns 404' do
delete namespace_project_issue_link_path(issue_links_params(id: issue_link.id))
expect(response).to have_http_status(401)
expect(response).to have_http_status(404)
end
end
end
......
......@@ -25,7 +25,7 @@ describe IssueLinks::CreateService, service: true do
end
it 'returns error' do
is_expected.to eq(message: 'No Issue found for given params', status: :error, http_status: 401)
is_expected.to eq(message: 'No Issue found for given params', status: :error, http_status: 404)
end
end
......@@ -35,7 +35,7 @@ describe IssueLinks::CreateService, service: true do
end
it 'returns error' do
is_expected.to eq(message: 'No Issue found for given params', status: :error, http_status: 401)
is_expected.to eq(message: 'No Issue found for given params', status: :error, http_status: 404)
end
it 'no relationship is created' do
......@@ -53,7 +53,7 @@ describe IssueLinks::CreateService, service: true do
it 'returns error' do
target_issue.project.add_guest(user)
is_expected.to eq(message: 'No Issue found for given params', status: :error, http_status: 401)
is_expected.to eq(message: 'No Issue found for given params', status: :error, http_status: 404)
end
it 'no relationship is created' do
......
......@@ -52,7 +52,7 @@ describe IssueLinks::DestroyService, service: true do
end
it 'returns error message' do
is_expected.to eq(message: 'Unauthorized', status: :error, http_status: 401)
is_expected.to eq(message: 'No Issue Link found', status: :error, http_status: 404)
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment