mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 09:01:55 +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 Step3Data step3Data;
|
||||
public Step4Data step4Data;
|
||||
public int errorCode = 0;
|
||||
|
||||
public Response(ParamsProvider paramsProvider) {
|
||||
super(paramsProvider);
|
||||
@ -1253,6 +1254,9 @@ public class DeviceConfig {
|
||||
this.step = 0x03;
|
||||
this.step3Data = new Step3Data(jsonPayload);
|
||||
}
|
||||
if (jsonPayload.has("errorCode")) {
|
||||
this.errorCode = jsonPayload.getInt("errorCode");
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
throw new JsonException("", e);
|
||||
}
|
||||
|
@ -163,9 +163,10 @@ public class GetHiChainRequest extends Request {
|
||||
if (!(receivedPacket instanceof HiChain.Response))
|
||||
throw new ResponseTypeMismatchException(receivedPacket, HiChain.Response.class);
|
||||
|
||||
// TODO: handle failure codes
|
||||
|
||||
HiChain.Response response = (HiChain.Response)receivedPacket;
|
||||
if (response.errorCode != 0) {
|
||||
throw new ResponseParseException("Got errorCode " + response.errorCode);
|
||||
}
|
||||
step = response.step;
|
||||
|
||||
LOG.debug("Response operationCode: " + operationCode + " - step: " + step);
|
||||
|
Loading…
Reference in New Issue
Block a user