mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-02-09 08:26:48 +01:00
Huawei: GetHiChainRequest: Add error handling
Parse the error code and throw an exception instead of doing strange things due to invalid step ID being used. To investigate issue #4061. Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
This commit is contained in:
parent
e51b55a38a
commit
cde10a6dce
@ -1225,6 +1225,7 @@ public class DeviceConfig {
|
|||||||
public Step2Data step2Data;
|
public Step2Data step2Data;
|
||||||
public Step3Data step3Data;
|
public Step3Data step3Data;
|
||||||
public Step4Data step4Data;
|
public Step4Data step4Data;
|
||||||
|
public int errorCode = 0;
|
||||||
|
|
||||||
public Response(ParamsProvider paramsProvider) {
|
public Response(ParamsProvider paramsProvider) {
|
||||||
super(paramsProvider);
|
super(paramsProvider);
|
||||||
@ -1253,6 +1254,9 @@ public class DeviceConfig {
|
|||||||
this.step = 0x03;
|
this.step = 0x03;
|
||||||
this.step3Data = new Step3Data(jsonPayload);
|
this.step3Data = new Step3Data(jsonPayload);
|
||||||
}
|
}
|
||||||
|
if (jsonPayload.has("errorCode")) {
|
||||||
|
this.errorCode = jsonPayload.getInt("errorCode");
|
||||||
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
throw new JsonException("", e);
|
throw new JsonException("", e);
|
||||||
}
|
}
|
||||||
|
@ -163,9 +163,10 @@ public class GetHiChainRequest extends Request {
|
|||||||
if (!(receivedPacket instanceof HiChain.Response))
|
if (!(receivedPacket instanceof HiChain.Response))
|
||||||
throw new ResponseTypeMismatchException(receivedPacket, HiChain.Response.class);
|
throw new ResponseTypeMismatchException(receivedPacket, HiChain.Response.class);
|
||||||
|
|
||||||
// TODO: handle failure codes
|
|
||||||
|
|
||||||
HiChain.Response response = (HiChain.Response)receivedPacket;
|
HiChain.Response response = (HiChain.Response)receivedPacket;
|
||||||
|
if (response.errorCode != 0) {
|
||||||
|
throw new ResponseParseException("Got errorCode " + response.errorCode);
|
||||||
|
}
|
||||||
step = response.step;
|
step = response.step;
|
||||||
|
|
||||||
LOG.debug("Response operationCode: " + operationCode + " - step: " + step);
|
LOG.debug("Response operationCode: " + operationCode + " - step: " + step);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user