Added more Error Handling and improved log readability

This commit is contained in:
genuineparts 2025-03-04 19:10:55 +01:00
parent d9dc23c524
commit 4adfd86fb5
3 changed files with 15 additions and 5 deletions

View file

@ -17,7 +17,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;
public class Main {
private static final String version = "0.5";
private static final String version = "0.6";
private static final HashMap<String, Integer> data = new HashMap<>();
public static Settings conf;
static OebbCheck check = new OebbCheck();

View file

@ -1,6 +1,7 @@
package be.jaud;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -68,7 +69,11 @@ public class OebbCheck {
private static JSONArray getData(String Station, String Time, String maxjourneys) throws IOException, URISyntaxException {
URL url = new URI("https://fahrplan.oebb.at/bin/stboard.exe/dn?L=vs_scotty.vs_liveticker&evaId=" + Station + "&boardType=dep&time="+ Time +"&productsFilter=1011110111011&additionalTime=0&maxJourneys=" + maxjourneys + "&outputMode=tickerDataOnly&start=yes&selectDate=today").toURL();
JSONObject jo = getJsonObject(url);
return jo.getJSONArray("journey");
if(jo!=null) {
return jo.getJSONArray("journey");
} else {
return null;
}
}
private static JSONObject getJsonObject(URL url) throws IOException {
@ -83,6 +88,11 @@ public class OebbCheck {
}
in.close();
String sub = content.substring(14);
return new JSONObject(sub);
try {
return new JSONObject(sub);
} catch (JSONException e){
LOG.error("Json Error! {} {}", e.getMessage(), sub);
return null;
}
}
}

View file

@ -4,14 +4,14 @@
<!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder
by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%ex%n
<pattern>%d{dd.MM.yyyy HH:mm:ss} [%thread] %-5level %logger{36} - %msg%ex%n
</pattern>
</encoder>
</appender>
<appender name="FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg %ex %n</pattern>
<pattern>%d{dd.MM.yyyy HH:mm:ss} [%thread] %-5level %logger{35} - %msg %ex %n</pattern>
</encoder>
<file>logs/logfile.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">