From: Eugene Crosser Date: Fri, 3 May 2013 11:11:13 +0000 (+0400) Subject: improve error messages X-Git-Url: http://www.average.org/gitweb/?p=YkNeoCR.git;a=commitdiff_plain;h=6f022e1e8402cf131c166bd98be511b7fc899fec improve error messages --- diff --git a/src/org/average/nfcauthcr/YkNeo.java b/src/org/average/nfcauthcr/YkNeo.java index 26a6853..6dcaf64 100644 --- a/src/org/average/nfcauthcr/YkNeo.java +++ b/src/org/average/nfcauthcr/YkNeo.java @@ -1,5 +1,6 @@ package org.average.nfcauthcr; +import java.lang.String; import java.io.IOException; import java.util.Arrays; @@ -32,8 +33,9 @@ public class YkNeo { int length = resp.length; if (resp[length - 2] != (byte)0x90 || resp[length - 1] != 0x00) { - throw new CRException( - "NFC Error code in the response to select"); + throw new CRException(String.format( + "NFC select error code: %02x:%02x", + resp[length - 2], resp[length - 1])); } byte[] crApdu = new byte[69]; crApdu[0] = 0x00; // CLA @@ -51,18 +53,20 @@ public class YkNeo { length = resp.length; if (resp[length - 2] != (byte)0x90 || resp[length - 1] != 0x00) { - throw new CRException( - "NFC Error code in the response to CR"); + throw new CRException(String.format( + "NFC CR error code: %02x:%02x", + resp[length - 2], resp[length - 1])); } if (length != 22) { - throw new CRException( - "NFC wrong response size: " + (length-2)); + throw new CRException(String.format( + "NFC wrong response size: got %d, need 20", + length-2)); } return Arrays.copyOf(resp, length-2); } catch (TagLostException e) { throw new CRException("NFC connection lost", e); } catch (IOException e) { - throw new CRException("NFC I/O error", e); + throw new CRException("NFC I/O: " + e.getMessage(), e); } } }