Commit d9f1872c8c58aa838cfe91fcc89250b1231ee51f
1 parent
4e3a7ed8
Device wizard: Rollback(delete) device when failed to save device credentials.
Showing
1 changed file
with
11 additions
and
3 deletions
... | ... | @@ -39,8 +39,8 @@ import { BaseData, HasId } from '@shared/models/base-data'; |
39 | 39 | import { EntityType } from '@shared/models/entity-type.models'; |
40 | 40 | import { DeviceProfileService } from '@core/http/device-profile.service'; |
41 | 41 | import { EntityId } from '@shared/models/id/entity-id'; |
42 | -import { Observable, of, Subscription } from 'rxjs'; | |
43 | -import { map, mergeMap, tap } from 'rxjs/operators'; | |
42 | +import { Observable, of, Subscription, throwError } from 'rxjs'; | |
43 | +import { catchError, map, mergeMap, tap } from 'rxjs/operators'; | |
44 | 44 | import { DeviceService } from '@core/http/device.service'; |
45 | 45 | import { ErrorStateMatcher } from '@angular/material/core'; |
46 | 46 | import { StepperSelectionEvent } from '@angular/cdk/stepper'; |
... | ... | @@ -335,7 +335,15 @@ export class DeviceWizardDialogComponent extends |
335 | 335 | mergeMap( |
336 | 336 | (deviceCredentials) => { |
337 | 337 | const deviceCredentialsValue = {...deviceCredentials, ...this.credentialsFormGroup.value.credential}; |
338 | - return this.deviceService.saveDeviceCredentials(deviceCredentialsValue); | |
338 | + return this.deviceService.saveDeviceCredentials(deviceCredentialsValue).pipe( | |
339 | + catchError(e => { | |
340 | + return this.deviceService.deleteDevice(device.id.id).pipe( | |
341 | + mergeMap(() => { | |
342 | + return throwError(e); | |
343 | + } | |
344 | + )); | |
345 | + }) | |
346 | + ); | |
339 | 347 | } |
340 | 348 | ), |
341 | 349 | map(() => true)); | ... | ... |