diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/StockQuote.java b/src/main/java/net/thauvin/erik/mobibot/modules/StockQuote.java index 41c5cce..3a00a5d 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/StockQuote.java +++ b/src/main/java/net/thauvin/erik/mobibot/modules/StockQuote.java @@ -113,7 +113,12 @@ public final class StockQuote extends ThreadedModule { try { final String error = json.getString("Error Message"); if (!error.isEmpty()) { - throw new ModuleException(debugMessage, Utils.unescapeXml(error)); + if (error.startsWith("Invalid API call.")) { + throw new ModuleException(debugMessage + ": " + Utils.unescapeXml(error), + "Invalid symbol."); + } else { + throw new ModuleException(debugMessage, Utils.unescapeXml(error)); + } } } catch (JSONException ignore) { // Do nothing. diff --git a/src/test/java/net/thauvin/erik/mobibot/modules/StockQuoteTest.java b/src/test/java/net/thauvin/erik/mobibot/modules/StockQuoteTest.java index 4b6e665..d9b7fb0 100644 --- a/src/test/java/net/thauvin/erik/mobibot/modules/StockQuoteTest.java +++ b/src/test/java/net/thauvin/erik/mobibot/modules/StockQuoteTest.java @@ -56,12 +56,15 @@ public class StockQuoteTest extends LocalProperties { public void testGetQuote() throws ModuleException { final String apiKey = LocalProperties.getProperty(StockQuote.ALPHAVANTAGE_API_KEY_PROP); try { - List messages = StockQuote.getQuote("AAPL", apiKey); + final List messages = StockQuote.getQuote("AAPL", apiKey); assertThat(messages).as("response not empty").isNotEmpty(); assertThat(messages.get(0).getMessage()).as("same stock symbol").contains("AAPL"); - messages = StockQuote.getQuote("012", apiKey); - assertThat(messages.get(0).isError()).as("invalid symbol error").isTrue(); + try { + StockQuote.getQuote("012", apiKey); + } catch (ModuleException e) { + assertThat(e.getMessage()).as("invalid symbol").containsIgnoringCase("invalid symbol"); + } assertThatThrownBy(() -> StockQuote.getQuote("test", "")).as("no API key").isInstanceOf( ModuleException.class).hasNoCause();