Skip to content

Commit

Permalink
fix(scan): handle an error on stopping a scan (#81)
Browse files Browse the repository at this point in the history
closes #80
  • Loading branch information
derevnjuk authored May 11, 2022
1 parent 4656d99 commit f770070
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
11 changes: 11 additions & 0 deletions packages/scan/src/Scan.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,5 +261,16 @@ describe('Scan', () => {

verify(mockedScans.stopScan(id)).never();
});

it('should handle and ignore an error', async () => {
when(mockedScans.stopScan(id)).thenReject(
new Error(
'Is not possible to change the scan status from done to stopped.'
)
);
when(mockedScans.getScan(id)).thenResolve({ status: ScanStatus.DONE });

await expect(scan.stop()).resolves.not.toThrow();
});
});
});
10 changes: 7 additions & 3 deletions packages/scan/src/Scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,14 @@ export class Scan {
}

public async stop(): Promise<void> {
await this.refreshState();
try {
await this.refreshState();

if (this.active) {
return this.scans.stopScan(this.id);
if (this.active) {
await this.scans.stopScan(this.id);
}
} catch {
// noop
}
}

Expand Down

0 comments on commit f770070

Please sign in to comment.