WaspW
Wasp17mo ago
mm

Uncaught Error when using prisma inside `app/src/server/utils.ts`

While working on creating jobs, I created a utility for logging inside the server/utils.ts
I wasn't checking the front-end from time to time as I was testing the job using postman.

However upon visiting the front-end @ localhost it doesn't work, it says uncaught error.

This was hard to debug as the terminal says wasp is building correctly, it's basically a runtime error. Had to check the which commit this started and check the code changes. At first I thought I did something wrong in the jobs.

Is this an expected behavior?

  • I attached the browser console error
Here is the code:

import { prisma } from "wasp/server";

export function requireNodeEnvVar(name: string): string {
  const value = process.env[name];
  if (value === undefined) {
    throw new Error(`Env var ${name} is undefined`);
  } else {
    return value;
  }
}

interface LogParams {
  message: string;
  level: 'info' | 'error' | 'job-info' | 'job-error' | string;
  data?: Record<string, any>;
}

export const logger = async ({ message, level = 'info', data = {} }: LogParams) => {
  await prisma.logs.create({
    data: {
      message: message,
      level: level,
      data: data,
    },
  });
}
image.png
Was this page helpful?