1
0
Fork 0
mirror of https://github.com/SinTan1729/chhoto-url synced 2024-10-16 21:33:54 -05:00

Cleaner fix using try-catch

This commit is contained in:
Sayantan Santra 2022-11-11 05:23:01 +00:00
parent 25c12960f3
commit 4e20204b16

View file

@ -18,17 +18,15 @@ public class Routes {
public static String addUrl(Request req, Response res) {
var body = req.body();
if (body.endsWith(";")) {
body = body + "$";
}
var split = body.split(";");
String longUrl = split[0];
if (split[1].equals("$")) {
split[1] = Utils.randomString();
String shortUrl;
try {
shortUrl = split[1];
} catch (ArrayIndexOutOfBoundsException e) {
shortUrl = Utils.randomString();
}
String shortUrl = split[1];
if (Utils.validate(shortUrl)) {
return urlRepository.addUrl(longUrl, shortUrl);