Skip to content

Commit a6bfbd1

Browse files
committed
fix: provide validation issues when attempting to create an instrument record with invalid data
1 parent da5b99c commit a6bfbd1

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

apps/api/src/instrument-records/instrument-records.service.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,12 @@ export class InstrumentRecordsService {
6767

6868
const parseResult = instrument.validationSchema.safeParse(this.parseJson(rawData));
6969
if (!parseResult.success) {
70-
console.error(parseResult.error.issues);
71-
throw new UnprocessableEntityException(
72-
`Data received for record does not pass validation schema of instrument '${instrument.id}'`
73-
);
70+
throw new UnprocessableEntityException({
71+
error: 'Unprocessable Entity',
72+
issues: parseResult.error.issues,
73+
message: `Data received for record does not pass validation schema of instrument '${instrument.id}'`,
74+
statusCode: 422
75+
});
7476
}
7577

7678
return this.instrumentRecordModel.create({

0 commit comments

Comments
 (0)