diff --git a/pages/_document.js b/pages/_document.tsx
similarity index 83%
rename from pages/_document.js
rename to pages/_document.tsx
index f967ac0..e71cc5c 100644
--- a/pages/_document.js
+++ b/pages/_document.tsx
@@ -2,14 +2,14 @@ import Document from "next/document";
import { ServerStyleSheet } from "styled-components";
export default class MyDocument extends Document {
- static async getInitialProps(ctx) {
+ static async getInitialProps(ctx: any) {
const sheet = new ServerStyleSheet(),
originalRenderPage = ctx.renderPage;
try {
ctx.renderPage = () =>
originalRenderPage({
- enhanceApp: App => props => sheet.collectStyles(),
+ enhanceApp: (App: any) => (props: any) => sheet.collectStyles(),
});
const initialProps = await Document.getInitialProps(ctx);
diff --git a/pages/api/[...id].ts b/pages/api/[...id].ts
index 502e403..ecb8c0c 100644
--- a/pages/api/[...id].ts
+++ b/pages/api/[...id].ts
@@ -18,23 +18,23 @@ type Parameters = {
};
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
- let axiosRes;
+ let getUser;
const params: Parameters = req.query,
- userid = req.query.id[0];
+ userId = req.query.id[0];
- if (!isSnowflake(userid))
+ if (!isSnowflake(userId))
return res.send({
- error: `Specify a valid Discord user ID! If everything looks correct and this still occurs, please contact @cnraddd on Twitter.`,
+ error: `That is not a valid snowflake ID!`,
});
try {
- axiosRes = await axios.get(`https://api.lanyard.rest/v1/users/${userid}`);
- } catch (err) {
- console.log(err);
+ getUser = await axios(`https://api.lanyard.rest/v1/users/${userId}`);
+ } catch (error) {
+ if (error.response.status === 404) return res.status(404).send({ error: "Invalid user!" });
- if (err.response.status === 404) return res.send({ error: "Invalid user!" });
+ console.log(error); // Only console log the error if its not a 404
- return res.send({
+ return res.status(400).send({
error: `Something went wrong! If everything looks correct and this still occurs, please contact @cnraddd on Twitter.`,
});
}
@@ -42,6 +42,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
res.setHeader("Content-Type", "image/svg+xml; charset=utf-8");
res.setHeader("content-security-policy", "default-src 'none'; img-src * data:; style-src 'unsafe-inline'");
- let svg = await renderCard(axiosRes.data, params);
+ const svg = await renderCard(getUser.data, params);
res.status(200).send(svg as any);
}
diff --git a/pages/index.tsx b/pages/index.tsx
index ab000c8..2fe73dc 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -1,5 +1,5 @@
import Head from "next/head";
-import styled, { createGlobalStyle, GlobalStyleComponent } from "styled-components";
+import styled, { createGlobalStyle } from "styled-components";
import { useState } from "react";
export default function Home() {
diff --git a/tsconfig.json b/tsconfig.json
index fd21301..fefbdbf 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -22,7 +22,7 @@
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
- "pages/_document.js"
+ "pages/_document.tsx"
],
"exclude": [
"node_modules"