Skip to content

Commit 1de1b87

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

File tree

3 files changed

+36
-44
lines changed

3 files changed

+36
-44
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: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -554,35 +554,31 @@ 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(
567-
html`Could not delete <strong>${profileName}</strong>, currently in
568-
use. Please remove browser profile from all Crawl Workflows to
569-
continue.`,
570-
),
571-
variant: "warning",
572-
duration: 15000,
573-
});
574-
} else {
575-
this.navigate.to(`${this.navigate.orgBasePath}/browser-profiles`);
564+
this.navigate.to(`${this.navigate.orgBasePath}/browser-profiles`);
576565

577-
this.notify.toast({
578-
message: msg(html`Deleted <strong>${profileName}</strong>.`),
579-
variant: "success",
580-
icon: "check2-circle",
581-
});
582-
}
566+
this.notify.toast({
567+
message: msg(html`Deleted <strong>${profileName}</strong>.`),
568+
variant: "success",
569+
icon: "check2-circle",
570+
});
583571
} catch (e) {
572+
let message = msg("Sorry, couldn't delete browser profile at this time.");
573+
if (isApiError(e) && e.details == "profile_in_use") {
574+
message = msg(
575+
html`Could not delete <strong>${profileName}</strong>, currently in
576+
use. Please remove browser profile from all crawl workflows to
577+
continue.`,
578+
);
579+
}
584580
this.notify.toast({
585-
message: msg("Sorry, couldn't delete browser profile at this time."),
581+
message: message,
586582
variant: "danger",
587583
icon: "exclamation-octagon",
588584
id: "browser-profile-error",

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

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -382,39 +382,35 @@ export class BrowserProfilesList extends BtrixElement {
382382

383383
private async deleteProfile(profile: Profile) {
384384
try {
385-
const data = await this.api.fetch<Profile & { error?: boolean }>(
385+
await this.api.fetch<{ error?: boolean }>(
386386
`/orgs/${this.orgId}/profiles/${profile.id}`,
387387
{
388388
method: "DELETE",
389389
},
390390
);
391391

392-
if (data.error && data.inUse) {
393-
this.notify.toast({
394-
message: msg(
395-
html`Could not delete <strong>${profile.name}</strong>, currently in
396-
use. Please remove browser profile from all Crawl Workflows to
397-
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();
411-
}
392+
this.notify.toast({
393+
message: msg(html`Deleted <strong>${profile.name}</strong>.`),
394+
variant: "success",
395+
icon: "check2-circle",
396+
id: "browser-profile-deleted-status",
397+
});
398+
399+
void this.fetchBrowserProfiles();
412400
} catch (e) {
401+
let message = msg("Sorry, couldn't delete browser profile at this time.");
402+
if (isApiError(e) && e.details == "profile_in_use") {
403+
message = msg(
404+
html`Could not delete <strong>${profile.name}</strong>, currently in
405+
use. Please remove browser profile from all crawl workflows to
406+
continue.`,
407+
);
408+
}
413409
this.notify.toast({
414-
message: msg("Sorry, couldn't delete browser profile at this time."),
410+
message: message,
415411
variant: "danger",
416412
icon: "exclamation-octagon",
417-
id: "browser-profile-deleted-status",
413+
id: "browser-profile-error",
418414
});
419415
}
420416
}

0 commit comments

Comments
 (0)