Skip to content

Commit bf2dc3d

Browse files
committed
Improve error message when saving media fails
1 parent bc4e68e commit bf2dc3d

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/components/file/media/media.repository.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,24 @@ export class MediaRepository extends CommonRepository {
154154
.apply(this.hydrate());
155155

156156
const result = await query.first();
157-
if (!result) {
158-
throw new ServerException('Failed to save media info');
157+
if (result) {
158+
return result.dto;
159159
}
160-
return result.dto;
160+
if (input.file) {
161+
const exists = await this.getBaseNode(input.file, 'FileVersion');
162+
if (!exists) {
163+
throw new NotFoundException(
164+
'Media could not be saved to nonexistent file',
165+
);
166+
}
167+
}
168+
if (input.id) {
169+
const exists = await this.getBaseNode(input.id, 'Media');
170+
if (!exists) {
171+
throw new NotFoundException('Media could not be found');
172+
}
173+
}
174+
throw new ServerException('Failed to save media info');
161175
}
162176
}
163177

0 commit comments

Comments
 (0)