Skip to content

Commit a4f7d3e

Browse files
committed
Replace undocumented error response with proper HTTPException
1 parent b99ed1a commit a4f7d3e

File tree

3 files changed

+44
-41
lines changed

3 files changed

+44
-41
lines changed

backend/btrixcloud/profiles.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ async def delete_profile(
395395
profile = await self.get_profile(profileid, org)
396396

397397
if profile.inUse:
398-
return {"error": "in_use"}
398+
raise HTTPException(status_code=400, detail="profile_in_use")
399399

400400
query: dict[str, object] = {"_id": profileid}
401401
if org:

frontend/src/pages/org/browser-profiles-detail.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -554,35 +554,36 @@ export class BrowserProfilesDetail extends BtrixElement {
554554
const profileName = this.profile!.name;
555555

556556
try {
557-
const data = await this.api.fetch<Profile & { error: boolean }>(
557+
await this.api.fetch<Profile>(
558558
`/orgs/${this.orgId}/profiles/${this.profile!.id}`,
559559
{
560560
method: "DELETE",
561561
},
562562
);
563563

564-
if (data.error && data.inUse) {
565-
this.notify.toast({
566-
message: msg(
564+
this.navigate.to(`${this.navigate.orgBasePath}/browser-profiles`);
565+
566+
this.notify.toast({
567+
message: msg(html`Deleted <strong>${profileName}</strong>.`),
568+
variant: "success",
569+
icon: "check2-circle",
570+
});
571+
} catch (e) {
572+
let message = msg(
573+
html`Sorry, couldn't delete browser profile at this time.`,
574+
);
575+
576+
if (isApiError(e)) {
577+
if (e.details === "profile_in_use") {
578+
message = msg(
567579
html`Could not delete <strong>${profileName}</strong>, currently in
568-
use. Please remove browser profile from all Crawl Workflows to
580+
use. Please remove browser profile from all crawl workflows to
569581
continue.`,
570-
),
571-
variant: "warning",
572-
duration: 15000,
573-
});
574-
} else {
575-
this.navigate.to(`${this.navigate.orgBasePath}/browser-profiles`);
576-
577-
this.notify.toast({
578-
message: msg(html`Deleted <strong>${profileName}</strong>.`),
579-
variant: "success",
580-
icon: "check2-circle",
581-
});
582+
);
583+
}
582584
}
583-
} catch (e) {
584585
this.notify.toast({
585-
message: msg("Sorry, couldn't delete browser profile at this time."),
586+
message: message,
586587
variant: "danger",
587588
icon: "exclamation-octagon",
588589
id: "browser-profile-error",

frontend/src/pages/org/browser-profiles-list.ts

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import type {
2323
APISortQuery,
2424
} from "@/types/api";
2525
import type { Browser } from "@/types/browser";
26+
import { isApiError } from "@/utils/api";
2627
import { html } from "@/utils/LiteElement";
2728
import { isArchivingDisabled } from "@/utils/orgs";
2829
import { tw } from "@/utils/tailwind";
@@ -382,39 +383,40 @@ export class BrowserProfilesList extends BtrixElement {
382383

383384
private async deleteProfile(profile: Profile) {
384385
try {
385-
const data = await this.api.fetch<Profile & { error?: boolean }>(
386+
await this.api.fetch<{ error?: boolean }>(
386387
`/orgs/${this.orgId}/profiles/${profile.id}`,
387388
{
388389
method: "DELETE",
389390
},
390391
);
391392

392-
if (data.error && data.inUse) {
393-
this.notify.toast({
394-
message: msg(
393+
this.notify.toast({
394+
message: msg(html`Deleted <strong>${profile.name}</strong>.`),
395+
variant: "success",
396+
icon: "check2-circle",
397+
id: "browser-profile-deleted-status",
398+
});
399+
400+
void this.fetchBrowserProfiles();
401+
} catch (e) {
402+
let message = msg(
403+
html`Sorry, couldn't delete browser profile at this time.`,
404+
);
405+
406+
if (isApiError(e)) {
407+
if (e.details === "profile_in_use") {
408+
message = msg(
395409
html`Could not delete <strong>${profile.name}</strong>, currently in
396-
use. Please remove browser profile from all Crawl Workflows to
410+
use. Please remove browser profile from all crawl workflows to
397411
continue.`,
398-
),
399-
variant: "warning",
400-
duration: 15000,
401-
});
402-
} else {
403-
this.notify.toast({
404-
message: msg(html`Deleted <strong>${profile.name}</strong>.`),
405-
variant: "success",
406-
icon: "check2-circle",
407-
id: "browser-profile-deleted-status",
408-
});
409-
410-
void this.fetchBrowserProfiles();
412+
);
413+
}
411414
}
412-
} catch (e) {
413415
this.notify.toast({
414-
message: msg("Sorry, couldn't delete browser profile at this time."),
416+
message: message,
415417
variant: "danger",
416418
icon: "exclamation-octagon",
417-
id: "browser-profile-deleted-status",
419+
id: "browser-profile-error",
418420
});
419421
}
420422
}

0 commit comments

Comments
 (0)