Skip to content

Commit 594b176

Browse files
Properly handle backend exception and front end error code (#7325)
1 parent 5229612 commit 594b176

File tree

4 files changed

+33
-17
lines changed

4 files changed

+33
-17
lines changed

packages/services/api/src/modules/schema/providers/schema-manager.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,21 @@ export class SchemaManager {
322322
};
323323
}
324324

325-
async getSchemaVersion(selector: TargetSelector & { versionId: string }) {
325+
async getSchemaVersion(
326+
selector: TargetSelector & { versionId: string },
327+
): Promise<SchemaVersion | null> {
326328
this.logger.debug('Fetching single schema version (selector=%o)', selector);
327-
const result = await this.storage.getVersion(selector);
329+
330+
if (isUUID(selector.versionId) === false) {
331+
this.logger.debug('Invalid UUID provided. (versionId=%s)', selector.versionId);
332+
return null;
333+
}
334+
335+
const result = await this.storage.getMaybeVersion(selector);
336+
337+
if (!result) {
338+
return null;
339+
}
328340

329341
return {
330342
projectId: selector.projectId,

packages/services/api/src/modules/shared/providers/storage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ export interface Storage {
405405
first: number | null;
406406
cursor: null | string;
407407
}): Promise<PaginatedSchemaVersionConnection>;
408-
getVersion(_: TargetSelector & { versionId: string }): Promise<SchemaVersion | never>;
408+
getMaybeVersion(_: TargetSelector & { versionId: string }): Promise<SchemaVersion | null>;
409409
deleteSchema(
410410
_: {
411411
serviceName: string;

packages/services/storage/src/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,8 +2316,8 @@ export async function createStorage(
23162316
return { serviceName: after.service_name, after: after.sdl, before: before?.sdl ?? null };
23172317
},
23182318

2319-
async getVersion({ projectId: project, targetId: target, versionId: version }) {
2320-
const result = await pool.one(sql`/* getVersion */
2319+
async getMaybeVersion({ projectId: project, targetId: target, versionId: version }) {
2320+
const result = await pool.maybeOne(sql`/* getMaybeVersion */
23212321
SELECT
23222322
${schemaVersionSQLFields(sql`sv.`)}
23232323
FROM schema_versions as sv
@@ -2330,6 +2330,10 @@ export async function createStorage(
23302330
LIMIT 1
23312331
`);
23322332

2333+
if (!result) {
2334+
return null;
2335+
}
2336+
23332337
return SchemaVersionModel.parse(result);
23342338
},
23352339
async getPaginatedSchemaVersionsForTargetId(args) {

packages/web/app/src/pages/target-history-version.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -644,17 +644,16 @@ function ActiveSchemaVersion(props: {
644644
targetSlug: props.targetSlug,
645645
versionId: props.versionId,
646646
},
647+
// don't fire query if this is an invalid UUID
647648
pause: !isValidVersionId,
648649
});
649650

650651
const { error } = query;
651-
652652
const isLoading = query.fetching || query.stale;
653653
const project = query.data?.project;
654654
const schemaVersion = project?.target?.schemaVersion;
655655
const projectType = query.data?.project?.type;
656656

657-
// Order of these conditionals is important...relocate carefully!
658657
if (!isValidVersionId) {
659658
return (
660659
<NotFoundContent
@@ -665,16 +664,6 @@ function ActiveSchemaVersion(props: {
665664
);
666665
}
667666

668-
if (!isLoading && !schemaVersion) {
669-
return (
670-
<NotFoundContent
671-
heading="Version ID does not exist"
672-
subheading="The provided version ID is not in our database."
673-
includeBackButton={false}
674-
/>
675-
);
676-
}
677-
678667
if (isLoading || !projectType) {
679668
return (
680669
<div className="flex size-full flex-col items-center justify-center self-center text-sm text-gray-500">
@@ -684,6 +673,17 @@ function ActiveSchemaVersion(props: {
684673
);
685674
}
686675

676+
// if we're here, we have a valid UUID for versionId but the schemaVersion is doesn't exist
677+
if (!schemaVersion) {
678+
return (
679+
<NotFoundContent
680+
heading="Schema Version not found."
681+
subheading="This schema version does not seem to exist anymore."
682+
includeBackButton={false}
683+
/>
684+
);
685+
}
686+
687687
if (error) {
688688
return (
689689
<div className="m-3 rounded-lg bg-red-500/20 p-8">

0 commit comments

Comments
 (0)