fix: imports + extra error type try and catch

This commit is contained in:
Gabriellvl 2025-05-19 17:44:13 +02:00
parent 219226148d
commit 2ac1b8187c
2 changed files with 4 additions and 3 deletions

View file

@ -19,7 +19,8 @@ import { putObject } from './service-helper.js';
import { fetchStudents } from './students.js';
import { ServerErrorException } from '../exceptions/server-error-exception.js';
import { BadRequestException } from '../exceptions/bad-request-exception.js';
import { ConflictException } from '../exceptions/conflict-exception';
import { ConflictException } from '../exceptions/conflict-exception.js';
import { PostgreSqlExceptionConverter } from "@mikro-orm/postgresql";
export async function fetchAssignment(classid: string, assignmentNumber: number): Promise<Assignment> {
const classRepository = getClassRepository();
@ -138,7 +139,7 @@ export async function deleteAssignment(classid: string, id: number): Promise<Ass
try {
await assignmentRepository.deleteByClassAndId(cls, id);
} catch (e: unknown) {
if (e instanceof ForeignKeyConstraintViolationException) {
if (e instanceof ForeignKeyConstraintViolationException || e instanceof PostgreSqlExceptionConverter) {
throw new ConflictException('Cannot delete assigment with questions or submissions');
} else {
throw e;