1

Implementing My Own Custom Error Handler

Profile picture
Mid-Level Software Engineer at Other17 days ago

Background

I have joined a new company recently and was tasked with building a Task Management System ( for clients and internal Employees ). So in short this software is going to be re-iterated again and again for improvement after we launch its first MVP ( targeted 2 months at max ).

Scenario

I have come across a use case where I want to handle errors using a custom error handler, its a function to which I pass any error thrown my APIs and based on error type ( error code a reference from prisma docs https://www.prisma.io/docs/orm/reference/error-reference) it returns a specific structured error response that can be useful for frontend devs and also help debug better.

Question

Is going this far for handling many errors worth it, i was recently listing to Alex for the Code Quality Course and what i understood its worth it as it would help me and my juniors debug better while in production and local development as well.

Tech Stack

Prisma ORM, Postgres, NextJS

33
1

Discussion

(1 comment)
  • 2
    Profile picture
    Eng @ Taro
    16 days ago

    it returns a specific structured error response that can be useful for frontend devs and also help debug better.

    Having a standardized structure for error responses makes a lot of sense, otherwise, the codebase can get messy in the future where there are conflicting ways of returning error responses.

    So in short this software is going to be re-iterated again and again for improvement after we launch its first MVP ( targeted 2 months at max ).

    Since you're launching the initial MVP, I would make sure the error response is very lightweight because you might need to flesh it out more in the future based on what kind of errors you get.

    what i understood its worth it as it would help me and my juniors debug better while in production and local development as well.

    I would make sure you have a good monitoring/logging/observability stack for aggregating all of the errors, too.