mirror of
https://github.com/SinTan1729/chhoto-url
synced 2025-04-19 03:10:00 -05:00
Cleaner fix using try-catch
This commit is contained in:
parent
25c12960f3
commit
4e20204b16
1 changed files with 6 additions and 8 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue