From dd239b86d03eb92dbb78ca881409a82830db3746 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 1 Oct 2014 20:39:50 +0200 Subject: [PATCH] Respond with 404 if job doesn't have a repository We have some jobs which doesn't have any repository in our DB. This is a quick fix which returns 404 for such a request instead of raising an error --- lib/travis/api/app/endpoint/jobs.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/travis/api/app/endpoint/jobs.rb b/lib/travis/api/app/endpoint/jobs.rb index 302112e0..9a70becf 100644 --- a/lib/travis/api/app/endpoint/jobs.rb +++ b/lib/travis/api/app/endpoint/jobs.rb @@ -12,7 +12,14 @@ class Travis::Api::App end get '/:id' do - respond_with service(:find_job, params) + job = service(:find_job, params).run + if job && job.repository + respond_with job + else + json = { error: { message: "The job(#{params[:id]}) couldn't be found" } } + status 404 + respond_with json + end end post '/:id/cancel' do