chore: minor changes & better error handling

Signed-off-by: alok8bb <alok8bb@gmail.com>
This commit is contained in:
2022-12-13 19:31:29 +05:30
parent 93b6fab121
commit 0a50433345
7 changed files with 47 additions and 17 deletions

View File

@ -1,13 +1,25 @@
export const setPaste = async (code: string): Promise<Response> => {
return await fetch("http://localhost:8080/bin/paste", {
method: "POST",
headers: { "Content-type": "text/plain" },
body: code,
});
import { SERVER_URL } from "../util";
export const setPaste = async (code: string) => {
try {
return await fetch(SERVER_URL + "/bin/paste", {
method: "POST",
headers: { "Content-type": "text/plain" },
body: code,
});
} catch (err) {
console.error(err);
return null;
}
};
export const getPaste = async (pasteId: string) => {
return await fetch(`http://localhost:8080/bin/paste/${pasteId}`);
try {
const response = await fetch(`${SERVER_URL}/bin/paste/${pasteId}`);
return response;
} catch (err) {
return null;
}
};
export interface SuccessResponse {