mirror of
https://github.com/0xShay/halflink.git
synced 2026-01-12 05:23:24 +00:00
Add more informative 404 message
This commit is contained in:
@@ -20,7 +20,7 @@ public class ShortLinkController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{code}")
|
@GetMapping("/{code}")
|
||||||
public ResponseEntity<Void> redirectToUrl(@PathVariable String code) {
|
public ResponseEntity<String> redirectToUrl(@PathVariable String code) {
|
||||||
ShortLink sl = shortLinkRepository.findByCode(code).orElse(null);
|
ShortLink sl = shortLinkRepository.findByCode(code).orElse(null);
|
||||||
if (sl != null) {
|
if (sl != null) {
|
||||||
sl.setClicks(sl.getClicks() + 1);
|
sl.setClicks(sl.getClicks() + 1);
|
||||||
@@ -30,7 +30,7 @@ public class ShortLinkController {
|
|||||||
.location(URI.create(sl.getUrl()))
|
.location(URI.create(sl.getUrl()))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
return ResponseEntity.notFound().build();
|
return ResponseEntity.status(404).body("The requested link was not found on the server");
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import { deleteLink, getLinkInfo } from "@/app/utils/api";
|
import { deleteLink, getLinkInfo } from "@/app/utils/api";
|
||||||
import { Clipboard } from "lucide-react";
|
import { Clipboard } from "lucide-react";
|
||||||
import { useParams } from "next/navigation";
|
import { redirect, useParams } from "next/navigation";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
@@ -28,8 +28,7 @@ export default function Home() {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
await deleteLink(params.id?.toString() || "");
|
await deleteLink(params.id?.toString() || "");
|
||||||
setSuccessMessage("Link deleted!");
|
redirect("/");
|
||||||
setErrorMessage(null);
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
setErrorMessage("Failed to delete the link. Please try again.");
|
setErrorMessage("Failed to delete the link. Please try again.");
|
||||||
|
|||||||
Reference in New Issue
Block a user