Open guyluz11 opened 1 year ago
I don't think that status code 207 should throw an error for Lifx
https://api.developer.lifx.com/reference/errors
It says on the API web page
207 Multi-Status | Inspect the response body to check status on individual operations.
Hey, it seems like the issue might be that the LIFXClient.setState
method expects a 207 in the http response, and if it receives one then handleResponse should return a LIFXResponse
, although that seems not to have happened in this case.
I've just released 0.0.15 which should be live soon, that adds the property http.Response response
to the LIFXError
class. With that you should be able to inspect the http.Response
that caused the error to throw. If you can paste the details what response is returned in the thrown error I'll be able to take a look and see what exactly caused it
Talking about responses, yours were quick :D
Here is the response that it throws with the new version 0.0.15
Ah looks like it returned a 202 instead of 207, I didn't realise the LIFX API could do that for set state. I'll make a tweak to fix that later today 👍
Have published version 0.0.16 now that should fix this, although let me know if the error still persists
Same (but different error?)
Closure: (Object, StackTrace) => dynamic from Function 'error': static.
#0 _ChunkedJsonParser.fail (dart:convert-patch/convert_patch.dart:1383:5)
#1 _ChunkedJsonParser.close (dart:convert-patch/convert_patch.dart:501:7)
#2 _parseJson (dart:convert-patch/convert_patch.dart:36:10)
#3 JsonDecoder.convert (dart:convert/json.dart:610:36)
#4 JsonCodec.decode (dart:convert/json.dart:216:41)
#5 jsonDecode (dart:convert/json.dart:155:10)
#6 new SetStateResponse (package:lifx_http_api/src/client/responses/set_state_response.dart:13:36)
#7 LIFXClient.setState (package:lifx_http_api/src/client/lifx_client.dart:76:11)
<asynchronous suspension>
#8 LifxWhiteEntity.turnOnLight (package:cbj_hub/infrastructure/devices/lifx/lifx_white/lifx_white_entity.dart:132:11)
<asynchronous suspension>
#9 LifxWhiteEntity.executeDeviceAction (package:cbj_hub/infrastructure/devices/lifx/lifx_white/lifx_white_entity.dart:96:12)
<asynchronous suspension>
It returns empty body, so you cant do jsonDecode(body)
on it lifx_http_api-0.0.16/lib/src/client/responses/set_state_response.dart:13
Found that to reproduce that you need to set
setState(fast: true, ....
Could it be that some modules do not support fast?
Ho so without fast it is working because of your fix, and with fast the body is empty so it crashes now on another part.
Hey sorry about the slow reply, I'm working on a fix for this at the moment in the add-tests
branch and will hopefully have something out later today
When adding fast option to the request the package returns error
Code
await client.setState(
Selector.id('myDeviceId'),
power: "on",
fast: true,
);
Error
Closure: (Object, StackTrace) => dynamic from Function 'error': static.
#0 _ChunkedJsonParser.fail (dart:convert-patch/convert_patch.dart:1383:5)
#1 _ChunkedJsonParser.close (dart:convert-patch/convert_patch.dart:501:7)
#2 _parseJson (dart:convert-patch/convert_patch.dart:36:10)
#3 JsonDecoder.convert (dart:convert/json.dart:610:36)
#4 JsonCodec.decode (dart:convert/json.dart:216:41)
#5 jsonDecode (dart:convert/json.dart:155:10)
#6 new SetStateResponse (package:lifx_http_api/src/client/responses/set_state_response.dart:13:36)
#7 LIFXClient.setState (package:lifx_http_api/src/client/lifx_client.dart:76:11)
<asynchronous suspension>
#8 main (file:///home/guyluz/Documents/git/lifx_http_api/example/main.dart:12:3)
<asynchronous suspension>
I think it is new that jsonEncode input is only Map<String, String> and not Map<String, dynamic>
In
lib/src/client/lifx_client.dart:72 we are doing body: jsonEncode(body),
but fast
input is bool and not string.
So it crashes there
I am managing to control my light using this package but I am getting errors in the response
So first of all let's check why it happens because it is extra stuff in my logs.
Second let's make this line throw the response status code and body as well https://github.com/nathanielgreen/lifx_http_api/blob/726a29d2076e3cc75c0a5e14c445d0914ef70c8c/lib/src/client/handle_response.dart#L11
In my case body was empty statusCode: 207 body: ''