improve error messages
authorEugene Crosser <crosser@average.org>
Fri, 3 May 2013 11:11:13 +0000 (15:11 +0400)
committerEugene Crosser <crosser@average.org>
Fri, 3 May 2013 11:11:13 +0000 (15:11 +0400)
src/org/average/nfcauthcr/YkNeo.java

index 26a685350657228170874dc39dc24042e47cc21a..6dcaf640f4d84bdca90ecf8395421d0772da4790 100644 (file)
@@ -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);
                }
        }
 }