From d4f8828fcf376cdda402cf327de743290de0b465 Mon Sep 17 00:00:00 2001
From: Schankula Christopher <schankuc@mcmaster.ca>
Date: Wed, 7 Mar 2018 10:01:38 -0500
Subject: [PATCH] error handling for nameToID

---
 src/biotree/TestBioTree.java | 5 ++++-
 src/biotree/WormsAPI.java    | 4 ++--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/biotree/TestBioTree.java b/src/biotree/TestBioTree.java
index 67005ca..3257bf2 100644
--- a/src/biotree/TestBioTree.java
+++ b/src/biotree/TestBioTree.java
@@ -2,13 +2,15 @@ package biotree;
 
 import static org.junit.Assert.*;
 
+import java.io.IOException;
+
 import org.junit.Before;
 import org.junit.Test;
 
 public class TestBioTree {
 
 	@Before
-	public static void main(String[] args) {
+	public static void main(String[] args) throws IOException {
 		BioTree.init();
 		BioTree.processRecord(125125);
 		BioTree.processRecord(125125);
@@ -29,6 +31,7 @@ public class TestBioTree {
 			//System.out.println(String.format("%-26s %s", nodes.get(i).getName(), nodes.get(i).getTaxonType()));
 		//}
 		BioTree.printTree();
+		System.out.println(WormsAPI.nameToID("Hello"));
 	}
 	
 
diff --git a/src/biotree/WormsAPI.java b/src/biotree/WormsAPI.java
index 79c0cca..ac595ae 100644
--- a/src/biotree/WormsAPI.java
+++ b/src/biotree/WormsAPI.java
@@ -38,11 +38,11 @@ public class WormsAPI {
 	 * @return Aphia (taxon) ID of given scientific name.
 	 * @throws IOException
 	 */
-	public static int nameToID(String scientificName) throws IOException {
+	public static Integer nameToID(String scientificName) throws IOException {
 		scientificName = repSpaces(scientificName);
 		String resp = makeRequest(
 				String.format("http://marinespecies.org/rest/AphiaIDByName/%s?marine_only=false", scientificName));
-
+		if (resp.length() == 0) return null;
 		return Integer.parseInt(resp);
 	}
 
-- 
GitLab