flexirest 1.8.9 → 1.9.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8eeb42973b47925b75719642de9f2ad0ff58795453b0843ae2119ad32be87f89
4
- data.tar.gz: fb6760cd9d4da6bbf4e3c653c7860790b3c259d7764f3ba4b2fc804461ff5d2b
3
+ metadata.gz: f402c30e90e85f106749a754d7783d2519da5b86cc0caf730799cac8a5f65c72
4
+ data.tar.gz: 29c6172196d8d09abbf37e2b40b0665d6b7d6498aa923b99c99e95683cf8c9c2
5
5
  SHA512:
6
- metadata.gz: 4ab9bd72452449e4e46332f44b100a7bace5e06334eb408f215956590b07c398e24a9a89144f6f6d99ae392730f91232ba5482e0d3075d45d7851fc67a2334aa
7
- data.tar.gz: af37f9b843b3bdf129078907468ac77f00019a9d499eecf8412a2c44d544b3792c5d0394449ae5a391f9e43dc6d107e707070772aea4f14fba4a6a3a05fde73c
6
+ metadata.gz: 502bdb7fb81e058703485d37c32f01f584ebdbc5a4d9eb37badf492847a9e9070f1705c06aee048397b61c16335b175b0447ccf8b6bf663080d83d84d6b64e8b
7
+ data.tar.gz: 4a2317aac7ea5adfafe440efb5401a6da26cb1a7a8f58d4d236a5978e8c239cd540d5a45a7c9bebc39d15065d07b75ab6410b3c42a53a8e5af986a984431afa4
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.9.0
4
+
5
+ Bugfix:
6
+
7
+ - Correctly handle errors in JSONAPI calls (thanks to François Ferrandis for the PR).
8
+
3
9
  ## 1.8.9
4
10
 
5
11
  Feature:
@@ -198,7 +198,7 @@ module Flexirest
198
198
 
199
199
  # Retrieve the resource(s) object or array from the data object
200
200
  records = body['data']
201
- return records unless records.present?
201
+ return body['errors'] unless records.present?
202
202
 
203
203
  # Convert the resource object to an array,
204
204
  # because it is easier to work with an array than a single object
@@ -1,3 +1,3 @@
1
1
  module Flexirest
2
- VERSION = "1.8.9"
2
+ VERSION = "1.9.10"
3
3
  end
@@ -239,6 +239,8 @@ module JsonAPIExample
239
239
  }
240
240
  }
241
241
 
242
+ get(:real_find, '/articles/:id')
243
+
242
244
  get(
243
245
  :find_lazy,
244
246
  '/articles/:id',
@@ -308,6 +310,27 @@ describe 'JSON API' do
308
310
  it 'should return a Flexirest::ResultIterator if the response contains more than one data instance' do
309
311
  expect(subject.find_all).to be_an_instance_of(Flexirest::ResultIterator)
310
312
  end
313
+
314
+ it 'should raise an error when response has "errors" key and no "data"' do
315
+ body = {
316
+ errors: [
317
+ {
318
+ title: "Record not found",
319
+ detail: "The record identified by 123456 could not be found",
320
+ code: "not_found",
321
+ status: "404",
322
+ }
323
+ ]
324
+ }
325
+ headers = { "Content-Type" => "application/vnd.api+json" }
326
+ expect_any_instance_of(Flexirest::Connection).
327
+ to receive(:get).with("/articles/123", an_instance_of(Hash)).
328
+ and_return(::FaradayResponseMock.new(OpenStruct.new(body: body.to_json, response_headers: headers, status: 404)))
329
+
330
+ expect(-> { JsonAPIExample::Article.real_find(123) }).to raise_error(Flexirest::HTTPNotFoundClientException) do |exception|
331
+ expect(exception.result.first.title).to eq("Record not found")
332
+ end
333
+ end
311
334
  end
312
335
 
313
336
  context 'attributes' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flexirest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.9
4
+ version: 1.9.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Jeffries
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-03 00:00:00.000000000 Z
11
+ date: 2020-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler