Merge branch 'api-errors-handling'
This commit is contained in:
commit
9c79c504c9
@ -6,7 +6,7 @@ module API
|
|||||||
skip_before_filter :authenticate!, only: :cor_preflight
|
skip_before_filter :authenticate!, only: :cor_preflight
|
||||||
|
|
||||||
before_filter :cor_filter
|
before_filter :cor_filter
|
||||||
before_filter :json_filter!
|
before_filter :json_filter!, except: :cor_preflight
|
||||||
|
|
||||||
def not_found
|
def not_found
|
||||||
head :not_found
|
head :not_found
|
||||||
@ -37,8 +37,11 @@ module API
|
|||||||
end
|
end
|
||||||
|
|
||||||
def json_filter!
|
def json_filter!
|
||||||
return if request.format.json?
|
if request.format.json? || request.accepts.include?(:json)
|
||||||
head :not_acceptable, content_type: 'application/json'
|
request.format = :json
|
||||||
|
else
|
||||||
|
head :not_acceptable, content_type: 'application/json'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -40,8 +40,8 @@ module AcceptanceHelpers
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def json
|
def json status = 200
|
||||||
expect(response).to be_success
|
expect(response.status).to be status
|
||||||
JSON.parse(response.body, symbolize_names: true)
|
JSON.parse(response.body, symbolize_names: true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user