Im fairly new to nest.js and following along a tutorial which you can see here:
https://www.freecodecamp.org/news/build-web-apis-with-nestjs-beginners-guide/
So Im building the validate.pipe.ts and Im getting an error on the following code.
import { Injectable, ArgumentMetadata, BadRequestException, ValidationPipe, UnprocessableEntityException } from '@nestjs/common';
@Injectable()
export class ValidateInputPipe extends ValidationPipe {
public async transform(value, metadata: ArgumentMetadata) {
try {
return await super.transform(value, metadata);
} catch (e) {
if (e instanceof BadRequestException) {
throw new UnprocessableEntityException(this.handleError(e.message.message));
}
}
}
private handleError(errors) {
return errors.map(error => error.constraints);
}
}
This is my code above and my error is
Property 'message' does not exist on type 'string'.
throw new UnprocessableEntityException(this.handleError(e.message.message));
2
Answers
I passed the e straight in and that seemed to fix the problem
it should be
not e.message.message in the below line