A Prisma error that covers all possible errors as mentioned in `Errors reference`
See original GitHub issueProblem
In any try/catch
that runs a prisma query you’d have to check if the error
is an instance of a specific prisma error in order to handle different kinds of errors and get the type-safety, for example if you want the the code
or message
property of an error.
If you want to catch all possible prisma errors you’d have to write a seperate if
statement for all of them, for example if you want to log the error.
if (error instanceof Prisma.PrismaClientKnownRequestError) {
log(error.code, error.message)
}
and so on...
If you dont do this, a possible error will not be logged because you are not checking if it’s an instance of. If you dont do any if
statements you dont have the type safety
catch (error) {
log(error.code) // type unknown, accepts a string;
log(error.message) // type unknown, accepts a string
}
Suggested solution
A prisma error that covers all exceptions
catch (error) {
if (error instanceof Prisma.Error) {
log(error.code, error.message) // this will log any error that prisma throws + typesafety. both code and message are a string
}
}
Alternatives
Additional context
Issue Analytics
- State:
- Created 2 years ago
- Reactions:9
- Comments:10 (1 by maintainers)
Top Results From Across the Web
Handling exceptions and errors (Reference)
This page covers how to handle exceptions and errors.
Read more >Error message reference
Errors that can occur include: The provided credentials for the database are invalid; There is no database server running under the provided hostname...
Read more >Configuring error formatting (Concepts)
This page explains how to configure the formatting of errors when using Prisma Client.
Read more >Advanced type safety (Reference)
Prisma Client provides full type safety for queries, even for partial queries or included relations. This page explains how to leverage the generated...
Read more >Prisma Client API (Reference)
API reference documentation for Prisma Client. ... console.error(e). await prisma. ... Determines the level and formatting of errors returned by Prisma.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
can specify it like this
refer this for more info
Crazy that you can get this highly detailed error message from the engine
But not this from the client to just deliver it in the response:
Of course you can still use schema validators, but then what’s the point of using an ORM at all? You’re going to be re-defining your schema just to get the validation working