How can I catch this kind of error? ```Unknown arg...
# orm-help
j
How can I catch this kind of error?
Copy code
Unknown arg `country` in data.country for type RegionUncheckedUpdateInput. Did you mean `countryId`? Available args:
type RegionUncheckedUpdateInput {
  id?: String | StringFieldUpdateOperationsInput
  name?: String | StringFieldUpdateOperationsInput
  createdAt?: DateTime | DateTimeFieldUpdateOperationsInput
  updatedAt?: DateTime | DateTimeFieldUpdateOperationsInput
  countryId?: String | StringFieldUpdateOperationsInput
}
This is probably not
PrismaClientKnownRequestError
cause it's missing my nest filter.
m
in your prisma service
Copy code
const { PrismaClient, Prisma } = require('@prisma/client');
In your error
middleware
catch these errors
Copy code
error instanceof Prisma.PrismaClientKnownRequestError ||
error instanceof Prisma.PrismaClientValidationError
......etc
are you using
nestjs-prisma
?
j
No, I'm not using this, should I? 😄
m
you need to add another method to catch
Prisma.PrismaClientValidationError
j
Sure, thank you. Gonna try this later. I just didn't know how to find the type of this particular error:)
👍 1
Btw, since I have you here - do you have any examples of real life nest/prisma or just express/prisma projects? I need some inspirations:)
m
you can start from here … https://www.prisma.io/nestjs

https://www.youtube.com/watch?v=mmbd5hcQUaY

https://github.com/notiz-dev/nestjs-prisma-starter/tree/main/src
j
Yeah, I went through this tutorial and it’s great:) But I’m looking for something more complex, with different modules, some middleware etc. But okay, if there’s nothing like that I’ll Just go step by step.
m
i have , but it is not open source project , sorry
j
Ok, thanks for your help:)
In case of anyone reading this later - catching the error is one thing but the best solution I found to this problem is to strip out any unwanted properties from the request earlier. It can be accomplished by passing ‘whitelist: true’ to validation pipe config.
104 Views