balvig/spyke

Accessing 404 status in the controller

LucasCioffi opened this issue · 2 comments

I see a 404 status in my log (which is expected for comment number 70):

Spyke (351.9ms)  GET http://localhost:3000/api/v1/articles/1/comments/70?id=70&param1=DEMO [404]

My controller code is below. Is there a method similar to @response.status which would let me see whether the comment was not found in the API?

def show
  @response =
    TestClient::Comments
    .with("articles/#{params[:article_id]}/comments/#{params[:comment_id]}")
    .find(params[:comment_id])
  respond_to do |format|
    format.json
  end
end

Hey there! Spyke will raise a Spyke::ResourceNotFound exception, if it gets a blank result from the API: https://github.com/balvig/spyke/blob/master/test/orm_test.rb#L28

It is therefore not dependent on the status code, but on the contents of the JSON.

Hope that helps?

Thank you; this is very helpful.