Refactoing: Replace Error Code with Exception
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
71b28222a7
commit
7fbc3f722c
|
@ -1,7 +1,10 @@
|
||||||
package link;
|
package link;
|
||||||
|
|
||||||
|
import exeptions.URLIsNotReachable;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
public class OnlineCheck {
|
public class OnlineCheck {
|
||||||
|
|
||||||
|
@ -18,8 +21,11 @@ public class OnlineCheck {
|
||||||
|
|
||||||
return http.getResponseCode();
|
return http.getResponseCode();
|
||||||
}
|
}
|
||||||
|
catch (UnknownHostException unknownHostException){
|
||||||
|
throw new URLIsNotReachable("The host of the url " + url + " could not be resolved.");
|
||||||
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
return 500; //TODO: seems smelly
|
throw new URLIsNotReachable("Something went wrong when trying to check if the url " + url + " is reachable. Make sure your internet connection is working: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue