Berian Chaiwa
06/15/2022, 9:52 AMPrismaClientKnownRequestError
into some nice json
object like : {code: "P2002",message:"some msg"}
? Can be helpful to reuse when looking up these error codes. If not, I will type them all out 🙂Nurul
06/15/2022, 10:06 AMRejectOnNotFound
, could you have a look at #12159 and let us know your thoughts.Peter Albert
06/15/2022, 10:10 AMYour Prisma schema is using features that are not supported for the version of the database.
Database version: {database_version}
Errors:
{errors}
,
P1016:
'Your raw query had an incorrect number of parameters. Expected: {expected}, actual: {actual}.',
P1017: 'Server has closed the connection.',
P2000:
"The provided value for the column is too long for the column's type. Column: {column_name}",
P2001:
'The record searched for in the where condition ({model_name}.{argument_name} = {argument_value}) does not exist',
P2002: 'Unique constraint failed on the {constraint}',
P2003: 'Foreign key constraint failed on the field: {field_name}',
P2004: 'A constraint failed on the database: {database_error}',
P2005:
"The value {field_value} stored in the database for the field {field_name} is invalid for the field's type",
P2006:
'The provided value {field_value} for {model_name} field {field_name} is not valid',
P2007: 'Data validation error {database_error}',
P2008: 'Failed to parse the query {query_parsing_error} at {query_position}',
P2009:
'Failed to validate the query: {query_validation_error} at {query_position}',
P2010: 'Raw query failed. Code: {code}. Message: {message}',
P2011: 'Null constraint violation on the {constraint}',
P2012: 'Missing a required value at {path}',
P2013:
'Missing the required argument {argument_name} for field {field_name} on {object_name}.',
P2014:
"The change you are trying to make would violate the required relation '{relation_name}' between the {model_a_name} and {model_b_name} models.",
P2015: 'A related record could not be found. {details}',
P2016: 'Query interpretation error. {details}',
P2017:
'The records for relation {relation_name} between the {parent_name} and {child_name} models are not connected.',
P2018: 'The required connected records were not found. {details}',
P2019: 'Input error. {details}',
P2020: 'Value out of range for the type. {details}',
P2021: 'The table {table} does not exist in the current database.',
P2022: 'The column {column} does not exist in the current database.',
P2023: 'Inconsistent column data: {message}',
P2024:
'Timed out fetching a new connection from the connection pool. (More info: http://pris.ly/d/connection-pool, Current connection limit: {connection_limit})',
P2025:
'An operation failed because it depends on one or more records that were required but not found. {cause}',
P2026:
"The current database provider doesn't support a feature that the query used: {feature}",
P2027:
'Multiple errors occurred on the database during query execution: {errors}',
P2030:
'Cannot find a fulltext index to use for the search, try adding a @@fulltext([Fields...]) to your schema',
P2033:
"A number used in the query does not fit into a 64 bit signed integer. Consider using BigInt as field type if you're trying to store large integers",
}Peter Albert
06/15/2022, 10:11 AMBerian Chaiwa
06/15/2022, 10:31 AMBerian Chaiwa
06/15/2022, 10:31 AMBerian Chaiwa
06/15/2022, 10:32 AMBerian Chaiwa
06/15/2022, 10:40 AMRejectOnNotFound
because I had trouble doing a trycatch and figuring out the error type for when something is not found. So now, with RejectOnNotFound
off , I just check if !result
then I return a custom error message.Berian Chaiwa
06/15/2022, 11:10 AMcatch
of my `resolver`:
catch (error) {
let errorFields: ErrorField[];
if (error instanceof PrismaClientKnownRequestError) {
const err = error;
const fields_list = error.meta?.target as string[]; // still nervous about this :)
if (fields_list) {
errorFields = fields_list.map((field) => ({
field: field,
message: PRISMA_ERROR_CODES[err.code],
}));
}
else {
errorFields = [
{
field: "unknown",
message: error.message,
},
];
}
} else if (error instanceof PrismaClientUnknownRequestError) {
errorFields = [
{
field: "unknown",
message: error.message,
},
];
} else {
// Send to Sentry,do not show the client the error
console.log(
"Something wrong happened during WaterTreatmentPlantCreate: ",
error
);
}
return {
__typename: "WaterTreatmentPlantCreateError",
message: `Failed to create WaterTreatmentPlant.`,
errors: errorFields!,
};
}