Standardize error handling for RemoveLog service endpoints
Return status 409 for errors
This commit is contained in:
parent
1cf298464a
commit
4a3807b21a
|
@ -64,7 +64,7 @@ class Travis::Api::App
|
|||
end
|
||||
end
|
||||
|
||||
patch '/:id/log', scope: :private do
|
||||
patch '/:id/log', scope: :private do |id|
|
||||
# PATCH method for `RemoveLog` service, since we are replacing log content
|
||||
service = self.service(:remove_log, params)
|
||||
begin
|
||||
|
@ -72,7 +72,10 @@ class Travis::Api::App
|
|||
rescue Travis::AuthorizationDenied => e
|
||||
status 401
|
||||
{ error: { message: e.message } }
|
||||
rescue Travis::JobUnfinished, Travis::LogAlreadyRemoved => e
|
||||
rescue Travis::JobUnfinished => jue
|
||||
status 409
|
||||
{ error: { message: "Job #{id} is not finished" } }
|
||||
rescue Travis::LogAlreadyRemoved => e
|
||||
status 409
|
||||
{ error: { message: e.message } }
|
||||
end
|
||||
|
|
|
@ -19,8 +19,11 @@ class Travis::Api::App
|
|||
status 401
|
||||
{ error: { message: ade.message } }
|
||||
rescue Travis::JobUnfinished => jue
|
||||
status 422
|
||||
status 409
|
||||
{ error: { message: "Job #{id} is not finished" } }
|
||||
rescue Travis::LogAlreadyRemoved => e
|
||||
status 409
|
||||
{ error: { message: e.message } }
|
||||
rescue => e
|
||||
status 500
|
||||
{ error: { message: "Unexpected error occurred: #{e.message}" } }
|
||||
|
|
|
@ -25,12 +25,12 @@ describe Travis::Api::App::Endpoint::Logs do
|
|||
end
|
||||
|
||||
context 'job is still running' do
|
||||
it 'returns status 422' do
|
||||
it 'returns status 409' do
|
||||
job.stubs(:finished?).returns false
|
||||
user.stubs(:permission?).with(:push, anything).returns true
|
||||
|
||||
response = patch("/logs/#{job.id}")
|
||||
response.status.should == 422
|
||||
response.status.should == 409
|
||||
JSON.parse(response.body)['error']['message'].should =~ Regexp.new("Job .*is (not |un)finished")
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user