BTW, this is no about Zinc, but about NeoJSON.

This is what I meant with variability that is hard to capture with a simple 
static type schema.

I have no time to try myself right now, but a custom mapping for ivar result 
(as in a block) might be able to see the difference and act accordingly.

> On 13 Dec 2017, at 07:59, Ben Coman <b...@openinworld.com> wrote:
> 
> 
> With... 
>   Object subclass: #BittrexResponse
>       instanceVariableNames: 'success message result'
>       classVariableNames: ''
>       package: 'Bittrex'
> 
>   Object subclass: #BittrexMarketSummary
>       instanceVariableNames: 'MarketName High Low Volume Last 
>                 BaseVolume TimeStamp Bid Ask OpenBuyOrders 
>                 OpenSellOrders PrevDay Created DisplayMarketName'
>       classVariableNames: ''
>       package: 'Bittrex'
> 
> this code works great when the response holds good data...
>   ZnClient new 
>       url: 
> 'https://bittrex.com/api/v1.1/public/getmarketSummary?market=BTC-LTC';
>       enforceHttpSuccess: true;
>       accept: ZnMimeType applicationJson;
>       contentReader: [ :entity | |reader|
>               reader := (NeoJSONReader on: entity readStream).
>               reader for: BittrexResponse do: [:m| 
>                       m mapInstVar: #success.
>                       m mapInstVar: #message.
>                       (m mapInstVar: #result) valueSchema: #ResultArray].
>               reader for: #ResultArray customDo: [ :mapping | 
>                        mapping listOfElementSchema: BittrexMarketSummary ].
>               reader mapInstVarsFor: BittrexMarketSummary. 
>       reader nextAs: BittrexResponse ];
>    get.
> 
> i.e. a raw response looking like this....
> (ZnClient new 
>       url: 
> 'https://bittrex.com/api/v1.1/public/getmarketsummary?market=BTC-LTC';
>       get) inspect.
> ==> 
> "'{""success"":true,""message"":"",""result"":[{""MarketName"":""BTC-LTC"",""High"":0.01982450,""Low"":0.01285257,""Volume"":1436429.81313360,""Last"":0.01842000,""BaseVolume"":24841.17217724,""TimeStamp"":""2017-12-13T05:56:25.937"",""Bid"":0.01840001,""Ask"":0.01842000,""OpenBuyOrders"":10140,""OpenSellOrders"":6306,""PrevDay"":0.01439800,""Created"":""2014-02-13T00:00:00""}]}'"
> 
> 
> But for bad response looking like this...
> (ZnClient new 
>       url: 
> 'https://bittrex.com/api/v1.1/public/getmarketsummary?market=INVALID';
>       get) inspect.
> ==> {"success":false,"message":"INVALID_MARKET","result":null}
> 
> the JSON handling code fails deep in the call stack with an error
>      "NeoJSONParseError: [ expected" 
> which is not so friendly for users of the Bittrex library.  
> 
> What are the different/recommended approaches with Zinc 
> for catching JSON errors such that I can pass "message" 
> as a higher level Error up the stack to the Bittrex user.
>  
>  cheers -ben


Reply via email to