Handle 404 not found error in API
This commit is contained in:
parent
b3cfa88bb9
commit
cd73a588b0
7
app/controllers/api/errors_controller.rb
Normal file
7
app/controllers/api/errors_controller.rb
Normal file
@ -0,0 +1,7 @@
|
||||
module API
|
||||
class ErrorsController < ApplicationController
|
||||
def not_found
|
||||
head :not_found
|
||||
end
|
||||
end
|
||||
end
|
@ -8,6 +8,7 @@ Rails.application.routes.draw do
|
||||
resources :sessions, only: :create
|
||||
resources :sounds, only: :show
|
||||
resources :tracks, only: :index
|
||||
match '*all', to: 'errors#not_found', via: :all
|
||||
end
|
||||
|
||||
resources :playlists
|
||||
|
@ -18,4 +18,12 @@ describe 'API application' do
|
||||
expect(response.body).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
describe 'not found' do
|
||||
it 'responds with a 404 when route does not exist' do
|
||||
get '/api/not_found', format: :json
|
||||
expect(response).to be_not_found
|
||||
expect(response.body).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user