Replies: 13 comments 4 replies
-
the same problem |
Beta Was this translation helpful? Give feedback.
-
Got the same if I don't add the ValidationPipe to the global:
but still couldn't make the translation work with DTO |
Beta Was this translation helpful? Give feedback.
-
The code can be found here https://github.com/toonvanstrijp/nestjs-i18n/tree/main/samples/dto-validation |
Beta Was this translation helpful? Give feedback.
-
I think I have more to do with graphql, but maybe you can help? |
Beta Was this translation helpful? Give feedback.
-
If you could provide me a repro. The exception filter is meant to be used with HTTP as far as I know. |
Beta Was this translation helpful? Give feedback.
-
no, there is support for graphql. Errors are even translated |
Beta Was this translation helpful? Give feedback.
-
so in what part, is the error you are facing |
Beta Was this translation helpful? Give feedback.
-
sorry for not explaining right away. I copied the source code myself and wrote the console.log. There are translations in object, but INTERNAL_SERVER_ERROR is returned to the graphql-playground |
Beta Was this translation helpful? Give feedback.
-
Hello, @rubiin |
Beta Was this translation helpful? Give feedback.
-
@rubiin any updates? |
Beta Was this translation helpful? Give feedback.
-
I still haven't solved this problem. Debugging didn't work, I just don't see where this message is coming from. |
Beta Was this translation helpful? Give feedback.
-
I've been messing around a bit to try to solve this problem and at the end I found a way to work around it: I created a filter class on my own (I named it 'GqlValidationExceptionFilter') and I had noticed that apollo wouldn't change the response regardless of what I returned on the filter catch function; I did some trial and error here and there, until I tried throwing "new Error("Test.")" inside my filter catch function instead of returning something. Finally, something that worked: Apollo would in that case catch the error and show it in the response. I helped myself by also logging things in the 'GraphQLModule.forRoot()' 'formatError(formattedError, error)' method in order to see what was it doing. At the end, I found out that by throwing a UserInputError - imported from '@nestjs/apollo' package - inside the filter with the already formatted i18nValidationError in the extensions field it would actually work! So here's the code of my filter: // gql-validation-exception.filter.ts
Now one can format the error here as intended. Probably not the best of solutions, but I hope this gives some tips to solve the issue. |
Beta Was this translation helpful? Give feedback.
-
Hello, I just tested nestjs-i18n in my nestjs application with a GraphQL api. I would like to use it for DTO validations, to translate my messages.
I have this setup:
When the validations are bad, I get this error.
Beta Was this translation helpful? Give feedback.
All reactions