@@ -75,7 +75,7 @@ export default createHandler(User);
7575If you want to use ` class-validator ` to validate request bodies and get them as DTOs, add it to your project by running:
7676
7777``` bash
78- $ yarn add class-validator
78+ $ yarn add class-validator class-transformer
7979```
8080
8181Then you can define your DTOs like:
@@ -134,7 +134,7 @@ export default createHandler(User);
134134
135135## Built-in pipes
136136
137- Pipes are being used to validate and transforms incoming values. The pipes can be added to the ` @Query ` decorator like:
137+ Pipes are being used to validate and transform incoming values. The pipes can be added to the ` @Query ` decorator like:
138138
139139``` ts
140140@Query (' isActive' , ParseBooleanPipe ) isActive : boolean
@@ -144,5 +144,39 @@ Pipes are being used to validate and transforms incoming values. The pipes can b
144144
145145| | Description | Remarks |
146146| ------------------ | -------------------------------------------- | --------------------------------------------- |
147- | ` ParseNumberPipe ` | Validates ands transforms ` Number ` strings. | Uses ` parseFloat ` under the hood |
148- | ` ParseBooleanPipe ` | Validates ands transforms ` Boolean ` strings. | Allows ` 'true' ` and ` 'false' ` as valid values |
147+ | ` ParseNumberPipe ` | Validates and transforms ` Number ` strings. | Uses ` parseFloat ` under the hood |
148+ | ` ParseBooleanPipe ` | Validates and transforms ` Boolean ` strings. | Allows ` 'true' ` and ` 'false' ` as valid values |
149+
150+
151+ ## Exceptions
152+
153+ The following built-in exceptions are provided by this package:
154+
155+ * ` NotFoundException `
156+ * ` BadRequestException `
157+
158+
159+ ### Custom exceptions
160+
161+ Any exception class that extends the base ` HttpException ` will be handled by the built-in error handler.
162+
163+ ``` ts
164+ import { HttpException } from ' @storyofams/next-api-decorators' ;
165+
166+ export class ForbiddenException extends HttpException {
167+ public constructor (message ? : string ) {
168+ super (403 , message );
169+ }
170+ }
171+ ```
172+
173+ Then later in the app, we can use it in our route handler:
174+
175+ ``` ts
176+ class Events {
177+ @Get ()
178+ public events() {
179+ throw new ForbiddenException ();
180+ }
181+ }
182+ ```
0 commit comments