ms-alumnos uses a globalDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Distribuidos-Org/ms-alumnos/llms.txt
Use this file to discover all available pages before exploring further.
MicroserviceExceptionFilter registered in main.ts to intercept every exception that escapes a message handler before it travels back across NATS. The filter converts whatever exception it receives into a typed RpcException so that callers always get a predictable error shape, regardless of whether the original problem was a validation failure, a missing record, or an unexpected runtime error.
MicroserviceExceptionFilter
The filter is defined insrc/common/filters/microservice-exception.filter.ts and implements NestJS’s ExceptionFilter interface. It catches all exception types via the @Catch() decorator (no argument) and returns an RxJS Observable that emits the wrapped error:
-
BadRequestException(validation failures) — NestJS’sValidationPipethrows aBadRequestExceptionwhose response body contains amessagearray of per-field error strings produced by class-validator. The filter extracts that array, joins the entries with,, and wraps the result in anRpcExceptionthat preserves the original HTTP status code (400). -
RpcException— if the exception is already anRpcException(thrown explicitly in service code), the filter passes it through unchanged withthrowError(() => exception). This prevents double-wrapping. -
Any other error — for any remaining exception type the filter constructs a new
RpcException. Thestatusis taken fromHttpException.getStatus()if the exception is an HTTP exception; otherwise it defaults to500. Themessageis taken fromError.messageif available, falling back to a generic string.
Service-level errors
AlumnosService throws RpcException directly whenever a requested student record does not exist. This keeps not-found errors clean and explicit — no HTTP layer is involved:
update and remove: if alumnoRepository.preload() returns undefined or delete affects zero rows, a 404 RpcException is thrown. Because the filter’s second branch passes RpcException through unchanged, these errors reach the caller exactly as written.
Error response shape
Every error that travels back over NATS has the following shape:status | Meaning |
|---|---|
400 | Validation failure — one or more DTO fields failed class-validator rules |
404 | Record not found — no Alumno with the given ID exists |
500 | Unexpected server error |
Callers should inspect the
status field in the error payload to determine how to handle the response — 400 indicates a problem with the request payload that the caller must fix, 404 means the resource does not exist, and 500 signals an internal problem on the microservice side.Validation errors
AlumnosService is protected by NestJS’s ValidationPipe, configured with whitelist: true and forbidNonWhitelisted: true. This means:
whitelist: true— any property not declared in the DTO class is silently stripped before the handler runs.forbidNonWhitelisted: true— if the stripped properties were present in the original payload, the pipe throws aBadRequestExceptionrather than silently discarding them.
@IsString(), @IsEmail(), @IsInt()). When the pipe detects one or more violations it collects all error messages into an array and throws a single BadRequestException.
Example — sending a payload with a missing required field and an unknown property:
message string is the join of all individual class-validator messages, separated by , . Callers can split on , to display per-field feedback to end users.