Skip to content

Errors

FieldsBadRequestException extends NestJS BadRequestException and is thrown when parsing or validation fails.

ts
try {
  Fields.parseAndValidate(query.fields, schema);
} catch (error) {
  if (error instanceof FieldsBadRequestException) {
    return error.getResponse();
  }
}

The response payload contains a stable message and error details:

ts
{
  message: 'Invalid fields query parameter',
  details: 'unknown field "name"',
  path: 'name'
}

Exception Filter

Use FieldsExceptionFilter to serialize these errors as HTTP 400 responses in NestJS:

ts
import { FieldsExceptionFilter } from '@querry-kit/nest-fields-query';

app.useGlobalFilters(new FieldsExceptionFilter());

The filter writes statusCode: 400 together with the structured NestJS error response.

Released under the MIT License.