CDRH / orchid

Rails Engine for site integration with CDRH API
MIT License
3 stars 0 forks source link

Problem with error checking #232

Closed wkdewey closed 2 years ago

wkdewey commented 2 years ago
def check_response
    if !@res || (@res.key?("error") && @res.error)
      flash[:error] = t "errors.api"
    end
  end

This code fails if @res is an APIBridge object, with undefined methodkey?' for #`.

techgique commented 2 years ago

Will mentioned Habeas exhibited this problem on the /search page. Habeas code at the time: https://github.com/CDRH/habeascorpus/commit/7733a3465c39f157ca20a35568495212f9f539de

wkdewey commented 2 years ago

When looking at individual items (I tried on https://github.com/whitmanarchive/whitmanarchive_rails), Orchid turns the item into a hash, which triggers the error undefined methoderror' for #`

wkdewey commented 2 years ago

This is due to how Orchid retrieves the items:

def item_retrieve(id)
   @res = @items_api.get_item_by_id(id).first # .first turns @res into a hash
wkdewey commented 2 years ago

Since other code expects @res to be a hash in the case of an individual item, I moved check_response out of show and changed item_retrieve as follows:

@res = @items_api.get_item_by_id(id)
    check_response
    @res = @res.first