BHelpful / MomentMeal

MomentMeal is a marketplace for food and recipes. We help you find and create the best recipes and meal plans for you.
https://momentmeal.com/
GNU Affero General Public License v3.0
13 stars 5 forks source link

[Minor]: Util for handling Prisma errors #438

Closed Andreasgdp closed 1 year ago

Andreasgdp commented 1 year ago

Description

Implement a util that can be used across all api services to handle Prisma errors.

Should help with

.catch((error: PrismaClientKnownRequestError) => {
    if (error.code === 'P2001') {
        throw new NotFoundException(STORES_EXCEPTION_MSG.NOT_FOUND);
    } else if (error.code === 'P2002') {
        throw new ForbiddenException(STORES_EXCEPTION_MSG.ALREADY_EXISTS);
    } else {
        throw new InternalServerErrorException(
            STORES_EXCEPTION_MSG.INTERNAL_SERVER_ERROR
        );
    }
});

And be something like

.catch((error: PrismaClientKnownRequestError) => {
    prismaErrorHandler(error, STORES_EXCEPTION_MSG);
});

UX

No response

Acceptance criteria

Comments / questions

No response

Code of Conduct