question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Log internal server errors during development by default

See original GitHub issue

Currently, I’m using the following code snippet for Next.js at the api/trpc/[trpc] route:

import * as trpcNext from "@trpc/server/adapters/next";

const __DEV__ = process.env.NODE_ENV !== "production";

export default trpcNext.createNextApiHandler({
  router: appRouter,
  createContext,
  onError: __DEV__
    ? ({ error, type, path, input }) => {
        if (error.code === "INTERNAL_SERVER_ERROR") {
          // eslint-disable-next-line no-console
          console.error("Error:", {
            type,
            path,
            input,
            cause: error.originalError,
          });
        }
      }
    : undefined,
});

I think it would be useful to always log unhandled errors (where error.code === "INTERNAL_SERVER_ERROR") to the server’s console like this during development, even when no onError is specified.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
KATTcommented, May 18, 2021

I love that you have so many ideas for improvements, if you need any guidance on how to contribute, let me know!

1reaction
kripodcommented, May 18, 2021

Why wouldn’t you want to do this in prod?

Maybe a default logger for development would be useful - feel free to make a PR!

The reason why I wouldn’t emit messages to the console is that HTTP responses will already have an error code of 500, which Vercel and other logging services keep track of. The message about the error returned in production already contains enough information to investigate on.

I’ll try creating some PRs soon – work makes me pretty busy nowadays, sorry about that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Debugging an IIS 500 – Internal server error - 4sysops
This error indicates that the number of incoming concurrent requests exceeded the number that your IIS application can process. This could be ...
Read more >
How to Fix a 500 Internal Server Error on Your WordPress Site
The 500 Internal Server Error status code occurs when the server encounters an error that prevents it from fulfilling the request.
Read more >
HTTP 500 Internal Server Error: What It Means & How to Fix It
An HTTP 500 internal server error is a general error message. It covers unexpected issues that don't fit into existing error codes. HTTP...
Read more >
500 Internal Server Error - What is it and how to resolve it?
500 Internal Server Error is a web based error. Learn how to troubleshoot an http 500 internal server error on an IIS server...
Read more >
Catching a 500 server error in Flask - python - Stack Overflow
Default exception handling that kicks in when an exception occurs that is not caught. In debug mode the exception will be re-raised immediately,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found