Francismiko
Francismiko
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Francismiko on 8/31/2023 in #questions
How does next13's /app routing api integrate Jest testing?
My test code looks like this:
describe(...
it(...
const mockInput = {...}
const mockRequest = {
method: "POST",
body: mockInput,
} as unknown as Request;

const mockResponse = {
status: jest.fn(),
json: jest.fn(),
} as unknown as Response;

await POST(mockRequest, mockResponse);

expect(mockResponse.status).toHaveBeenCalledWith(200);
expect(mockResponse.json).toHaveBeenCalledWith(expect.anything());
)
)
describe(...
it(...
const mockInput = {...}
const mockRequest = {
method: "POST",
body: mockInput,
} as unknown as Request;

const mockResponse = {
status: jest.fn(),
json: jest.fn(),
} as unknown as Response;

await POST(mockRequest, mockResponse);

expect(mockResponse.status).toHaveBeenCalledWith(200);
expect(mockResponse.json).toHaveBeenCalledWith(expect.anything());
)
)
And the types passed in by my POST are the native Request and Response types. The result is this error: expect(jest.fn()).toHaveBeenCalledWith(...expected) Expected: 200 Number of calls: 0 Looks like the request is not being impersonated to run? thus not getting any response.
3 replies
TTCTheo's Typesafe Cult
Created by Francismiko on 8/13/2023 in #questions
How Next.js 13 middleware is used as error handling?
8 replies
TTCTheo's Typesafe Cult
Created by Francismiko on 8/13/2023 in #questions
How Next.js 13 middleware is used as error handling?
I don't want to add a try catch module to each of my api codes. Doing so would defeat my original intention of using middleware to catch errors. So do you guys have any good insights? blessjmg
8 replies
TTCTheo's Typesafe Cult
Created by Francismiko on 8/13/2023 in #questions
How Next.js 13 middleware is used as error handling?
But this doesn't work, I can't catch related errors thrown by my api, for example my POST api:
const inputSchema = z.object({
message: z.string(),
});

export async function POST(req: Request) {
const body = await req.json();
const input = inputSchema.parse(body); // (input invalid parmas) => throws ZodError

return new Response(JSON.stringify({ status: "ok" }));
}
const inputSchema = z.object({
message: z.string(),
});

export async function POST(req: Request) {
const body = await req.json();
const input = inputSchema.parse(body); // (input invalid parmas) => throws ZodError

return new Response(JSON.stringify({ status: "ok" }));
}
8 replies
TTCTheo's Typesafe Cult
Created by Francismiko on 8/13/2023 in #questions
How Next.js 13 middleware is used as error handling?
Here is my existing code
export function middleware(request: Request) {
try {
const apiKey = request.headers.get("API_KEY");
if (apiKey !== env.API_KEY) {
return new Response(JSON.stringify({ error: "Invalid API key" }), {
status: 401,
});
}
return NextResponse.next();
} catch (err) {
if (error instanceof z.ZodError) {
return new Response(JSON.stringify(error.issues), { status: 422 });
}

return new Response(JSON.stringify(error), { status: 500 });
}
}
export function middleware(request: Request) {
try {
const apiKey = request.headers.get("API_KEY");
if (apiKey !== env.API_KEY) {
return new Response(JSON.stringify({ error: "Invalid API key" }), {
status: 401,
});
}
return NextResponse.next();
} catch (err) {
if (error instanceof z.ZodError) {
return new Response(JSON.stringify(error.issues), { status: 422 });
}

return new Response(JSON.stringify(error), { status: 500 });
}
}
8 replies
CCConvex Community
Created by Francismiko on 7/12/2023 in #support-community
The storage API returns a status code of 503
Thank you for your efforts, if there are any problems, I will continue to feedback🐎
9 replies
CCConvex Community
Created by Francismiko on 7/12/2023 in #support-community
The storage API returns a status code of 503
Is there an estimated repair time? Since my project has been deployed to the production environment, this will have a certain impact🏄‍♂️
9 replies
CCConvex Community
Created by Francismiko on 7/12/2023 in #support-community
The storage API returns a status code of 503
Works fine in most cases
9 replies
CCConvex Community
Created by Francismiko on 7/12/2023 in #support-community
The storage API returns a status code of 503
const postUrl = await getUrl() const result = await fetch(postUrl, { method: "POST", headers: { "Content-Type": file.type }, body: file, }) const res = await result.json() console.log({ res })
9 replies
CCConvex Community
Created by Francismiko on 7/12/2023 in #support-community
The storage API returns a status code of 503
res: code: "Overloaded" message: "InternalServerError: Your request couldn't be completed. Try again later."
9 replies
CCConvex Community
Created by Francismiko on 6/29/2023 in #support-community
How can I still deploy locally with Vercel?
Ah~ When I temporarily removed the relevant configuration files and variables from vercel in env locally, the problem was solved. I have to say that the development team has done very carefully in these details, reducing the possibility of mistakes caused by many mistakes in development 🥰
3 replies
CCConvex Community
Created by Francismiko on 6/29/2023 in #general
Data import
In the dashboard, I try to add the json array directly to the error
7 replies
CCConvex Community
Created by Francismiko on 6/29/2023 in #general
Data import
Oye, I found this relevant documentation entry, thank you!https://docs.convex.dev/cli#import-a-file-into-convex
7 replies
CCConvex Community
Created by Francismiko on 6/29/2023 in #general
Data import
something like this: This document is invalid, fix any errors to continue
7 replies
CCConvex Community
Created by Francismiko on 6/27/2023 in #support-community
`useConvexAuth()` returns undefined (resolved: two versions of convex package loaded)
@ballingt yep, I'm using @clerk/clerk-react": ^4.15.3 . This is my root render code
const convex = new ConvexReactClient(
process.env.NEXT_PUBLIC_CONVEX_URL as string,
{ verbose: true },
)

<ClerkAuthProvider publishableKey={process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY}>
<AppProvider...>
<ConvexProviderWithClerk client={convex}>
<AppLayout...>
const convex = new ConvexReactClient(
process.env.NEXT_PUBLIC_CONVEX_URL as string,
{ verbose: true },
)

<ClerkAuthProvider publishableKey={process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY}>
<AppProvider...>
<ConvexProviderWithClerk client={convex}>
<AppLayout...>
14 replies
CCConvex Community
Created by Francismiko on 6/27/2023 in #support-community
`useConvexAuth()` returns undefined (resolved: two versions of convex package loaded)
No effect, I'm looking for where the error occurs👨‍💻
14 replies
CCConvex Community
Created by Francismiko on 6/27/2023 in #support-community
`useConvexAuth()` returns undefined (resolved: two versions of convex package loaded)
I am using the Yarn 3.0 version as a package management tool. It is very strange. I have never encountered this error before.😂
14 replies
CCConvex Community
Created by Francismiko on 6/27/2023 in #support-community
`useConvexAuth()` returns undefined (resolved: two versions of convex package loaded)
The same error happens on isLoading
14 replies
CCConvex Community
Created by Francismiko on 6/27/2023 in #support-community
`useConvexAuth()` returns undefined (resolved: two versions of convex package loaded)
There is such a console error:
app-layout.tsx:127 Uncaught TypeError: Cannot destruction property 'isAuthenticated' of '(0 , convex_react__WEBPACK_IMPORTED_MODULE_8__.useConvexAuth)(...)' as it is undefined.
at Authenticated (app-layout.tsx:127:11)
at renderWithHooks (react-dom. development. js:16305:1)
at mountIndeterminateComponent (react-dom. development. js:20074:1)
at beginWork (react-dom. development. js:21587:1)
at HTMLUnknownElement.callCallback (react-dom.development.js:4164:1)
at Object.invokeGuardedCallbackDev (react-dom.development.js:4213:1)
at invokeGuardedCallback (react-dom. development. js:4277:1)
at beginWork$1 (react-dom. development. js:27451:1)
at performUnitOfWork (react-dom. development. js:26557:1)
at workLoopSync (react-dom. development. js:26466:1)
at renderRootSync (react-dom. development. js:26434:1)
at performConcurrentWorkOnRoot (react-dom. development. js:25738:1)
at workLoop (scheduler. development. js:266:1)
at flushWork (scheduler. development. js:239:1)
at MessagePort.performWorkUntilDeadline (scheduler.development.js:533:1)
app-layout.tsx:127 Uncaught TypeError: Cannot destruction property 'isAuthenticated' of '(0 , convex_react__WEBPACK_IMPORTED_MODULE_8__.useConvexAuth)(...)' as it is undefined.
at Authenticated (app-layout.tsx:127:11)
at renderWithHooks (react-dom. development. js:16305:1)
at mountIndeterminateComponent (react-dom. development. js:20074:1)
at beginWork (react-dom. development. js:21587:1)
at HTMLUnknownElement.callCallback (react-dom.development.js:4164:1)
at Object.invokeGuardedCallbackDev (react-dom.development.js:4213:1)
at invokeGuardedCallback (react-dom. development. js:4277:1)
at beginWork$1 (react-dom. development. js:27451:1)
at performUnitOfWork (react-dom. development. js:26557:1)
at workLoopSync (react-dom. development. js:26466:1)
at renderRootSync (react-dom. development. js:26434:1)
at performConcurrentWorkOnRoot (react-dom. development. js:25738:1)
at workLoop (scheduler. development. js:266:1)
at flushWork (scheduler. development. js:239:1)
at MessagePort.performWorkUntilDeadline (scheduler.development.js:533:1)
14 replies