Skip to content

Commit

Permalink
Add error handling and messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
brianjgeiger committed May 14, 2024
1 parent 66ec51a commit 404710a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
21 changes: 18 additions & 3 deletions app/packages/addons-service/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import Store from '@ember-data/store';
import { tracked } from '@glimmer/tracking';
import { Task, task } from 'ember-concurrency';
import { taskFor } from 'ember-concurrency-ts';
import Intl from 'ember-intl/services/intl';
import Toast from 'ember-toastr/services/toast';

import NodeModel from 'ember-osf-web/models/node';
import CurrentUserService from 'ember-osf-web/services/current-user';
Expand All @@ -22,6 +24,7 @@ import ExternalStorageServiceModel from 'ember-osf-web/models/external-storage-s
import ExternalComputingServiceModel from 'ember-osf-web/models/external-computing-service';
import ExternalCitationServiceModel from 'ember-osf-web/models/external-citation-service';
import { notifyPropertyChange } from '@ember/object';
import captureException, { getApiErrorMessage } from 'ember-osf-web/utils/capture-exception';

export type AllProviderTypes =
ExternalStorageServiceModel |
Expand All @@ -44,6 +47,9 @@ interface ProviderTypeMapper {


export default class Provider {
@service toast!: Toast;
@service intl!: Intl;

@tracked node?: NodeModel;
@tracked serviceNode?: ResourceReferenceModel;

Expand Down Expand Up @@ -123,9 +129,18 @@ export default class Provider {
@task
@waitFor
async removeConfiguredAddon(selectedConfiguration: AllConfiguredAddonTypes) {
this.configuredAddons?.removeObject(selectedConfiguration);
notifyPropertyChange(this, 'configuredAddons');
await selectedConfiguration?.destroyRecord();
const errorMessage = this.intl.t('addons.provider.remove-configured-addon-error');
const successMessage = this.intl.t('addons.provider.remove-configured-addon-success');
try {
await selectedConfiguration?.destroyRecord();
this.configuredAddons?.removeObject(selectedConfiguration);
notifyPropertyChange(this, 'configuredAddons');
this.toast.success(successMessage);
} catch (e) {
captureException(e, { errorMessage });
this.toast.error(getApiErrorMessage(e), errorMessage);
return;
}
}

@task
Expand Down
3 changes: 3 additions & 0 deletions translations/en-us.yml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ dashboard:

addons:
heading: 'Add-ons'
provider:
remove-configured-addon-success: 'You have successfully removed this addon'
remove-configured-addon-error: 'There was a problem removing this addon'
list:
authorized-accounts-for-provider: 'Authorized accounts for {providerName}'
authorized-accounts: 'Authorized accounts'
Expand Down

0 comments on commit 404710a

Please sign in to comment.