Improve error handling on upload
This commit is contained in:
19
src/pages/api/share/[shareId]/exists.ts
Normal file
19
src/pages/api/share/[shareId]/exists.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import { ShareDocument } from "../../../../types/Appwrite.type";
|
||||
import awServer from "../../../../utils/appwriteServer.util";
|
||||
|
||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
const shareId = req.query.shareId as string;
|
||||
let doesExists;
|
||||
|
||||
try {
|
||||
await awServer.database.getDocument<ShareDocument>("shares", shareId);
|
||||
doesExists = true;
|
||||
} catch {
|
||||
doesExists = false;
|
||||
}
|
||||
|
||||
res.status(200).json({ exists: doesExists });
|
||||
};
|
||||
|
||||
export default handler;
|
||||
Reference in New Issue
Block a user