@@ -26,12 +26,11 @@ import {
26
26
EventCallback ,
27
27
GetLogs ,
28
28
Subscribe ,
29
+ ErrorCode ,
29
30
} from '../types' ;
31
+ import { PolymathError } from '../PolymathError' ;
30
32
import assert from '../utils/assert' ;
31
33
32
- const SUBSCRIPTION_NOT_FOUND = 'SUBSCRIPTION_NOT_FOUND' ;
33
- const SUBSCRIPTION_ALREADY_PRESENT = 'SUBSCRIPTION_ALREADY_PRESENT' ;
34
-
35
34
export default abstract class ContractWrapper {
36
35
protected contract : Promise < BaseContract > ;
37
36
@@ -106,7 +105,7 @@ export default abstract class ContractWrapper {
106
105
107
106
protected unsubscribeInternal ( filterToken : string , err ?: Error ) : void {
108
107
if ( _ . isUndefined ( this . _filters [ filterToken ] ) ) {
109
- throw new Error ( SUBSCRIPTION_NOT_FOUND ) ;
108
+ throw new PolymathError ( { code : ErrorCode . NotFound } ) ;
110
109
}
111
110
if ( ! _ . isUndefined ( err ) ) {
112
111
const callback = this . _filterCallbacks [ filterToken ] ;
@@ -181,7 +180,7 @@ export default abstract class ContractWrapper {
181
180
182
181
private _startBlockAndLogStream ( isVerbose : boolean ) : void {
183
182
if ( ! _ . isUndefined ( this . _blockAndLogStreamerIfExists ) ) {
184
- throw new Error ( SUBSCRIPTION_ALREADY_PRESENT ) ;
183
+ throw new PolymathError ( { code : ErrorCode . AlreadyExists } ) ;
185
184
}
186
185
this . _blockAndLogStreamerIfExists = new BlockAndLogStreamer (
187
186
this . _blockstreamGetBlockOrNullAsync . bind ( this ) ,
@@ -227,7 +226,7 @@ export default abstract class ContractWrapper {
227
226
228
227
private _stopBlockAndLogStream ( ) : void {
229
228
if ( _ . isUndefined ( this . _blockAndLogStreamerIfExists ) ) {
230
- throw new Error ( SUBSCRIPTION_NOT_FOUND ) ;
229
+ throw new PolymathError ( { code : ErrorCode . NotFound } ) ;
231
230
}
232
231
this . _blockAndLogStreamerIfExists . unsubscribeFromOnLogAdded ( this . _onLogAddedSubscriptionToken as string ) ;
233
232
this . _blockAndLogStreamerIfExists . unsubscribeFromOnLogRemoved ( this . _onLogRemovedSubscriptionToken as string ) ;
0 commit comments