File tree Expand file tree Collapse file tree 1 file changed +7
-9
lines changed
apps/api/src/instrument-records Expand file tree Collapse file tree 1 file changed +7
-9
lines changed Original file line number Diff line number Diff line change @@ -336,23 +336,21 @@ export class InstrumentRecordsService {
336336
337337 private async createSubjectIfNotFound ( subjectId : string ) {
338338 try {
339- await this . subjectsService . findById ( subjectId ) ;
339+ return await this . subjectsService . findById ( subjectId ) ;
340340 } catch ( exception ) {
341341 if ( exception instanceof NotFoundException ) {
342342 const addedSubject : CreateSubjectDto = {
343343 id : subjectId
344344 } ;
345345 try {
346- await this . subjectsService . create ( addedSubject ) ;
346+ return await this . subjectsService . create ( addedSubject ) ;
347347 } catch ( prismaError ) {
348- if ( prismaError instanceof Prisma . PrismaClientKnownRequestError ) {
349- // The .code property can be accessed in a type-safe manner
350- // eslint-disable-next-line max-depth
351- if ( prismaError . code === 'P2002' ) {
352- console . error ( prismaError ) ;
353- }
348+ if ( prismaError instanceof Prisma . PrismaClientKnownRequestError && prismaError . code === 'P2002' ) {
349+ console . error ( prismaError ) ;
350+ return await this . subjectsService . findById ( subjectId ) ;
351+ } else {
352+ throw prismaError ;
354353 }
355- throw prismaError ;
356354 }
357355 } else {
358356 throw exception ;
You can’t perform that action at this time.
0 commit comments