Skip to content

Commit

Permalink
refactor: renamed items in RxErrorCode
Browse files Browse the repository at this point in the history
internal refactor
  • Loading branch information
benlesh committed May 10, 2019
1 parent 4da0e68 commit 4959bd5
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/internal/util/ArgumentOutOfRangeError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ ArgumentOutOfRangeErrorImpl.prototype = Object.create(Error.prototype);
export const ArgumentOutOfRangeError: ArgumentOutOfRangeErrorCtor = ArgumentOutOfRangeErrorImpl as any;

export function createOutOfRangeError() {
return createRxError('out of range', RxErrorCode.OutOfRangeError, ArgumentOutOfRangeError);
return createRxError('out of range', RxErrorCode.OutOfRange, ArgumentOutOfRangeError);
}
2 changes: 1 addition & 1 deletion src/internal/util/ObjectUnsubscribedError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ ObjectUnsubscribedErrorImpl.prototype = Object.create(Error.prototype);
export const ObjectUnsubscribedError: ObjectUnsubscribedErrorCtor = ObjectUnsubscribedErrorImpl as any;

export function createObjectUnsubscribedError() {
return createRxError('object unsubscribed', RxErrorCode.ObjectUnsubscribedError, ObjectUnsubscribedError);
return createRxError('object unsubscribed', RxErrorCode.ObjectUnsubscribed, ObjectUnsubscribedError);
}
2 changes: 1 addition & 1 deletion src/internal/util/TimeoutError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ TimeoutErrorImpl.prototype = Object.create(Error.prototype);
export const TimeoutError: TimeoutErrorCtor = TimeoutErrorImpl as any;

export function createTimeoutError() {
return createRxError('observable timed out', RxErrorCode.TimeoutError, TimeoutError);
return createRxError('observable timed out', RxErrorCode.Timeout, TimeoutError);
}
2 changes: 1 addition & 1 deletion src/internal/util/UnsubscriptionError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ export const UnsubscriptionError: UnsubscriptionErrorCtor = UnsubscriptionErrorI

export function createTeardownError(errors: any[]) {
const error: any = new UnsubscriptionError(errors);
error.__rxjsErrorCode = RxErrorCode.TeardownError;
error.__rxjsErrorCode = RxErrorCode.Teardown;
return error;
}
22 changes: 14 additions & 8 deletions src/internal/util/errors.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@

/**
* Used to identify different types of RxJS errors.
*/
export const enum RxErrorCode {
Empty = 0,
OutOfRangeError = 1,
ObjectUnsubscribedError = 2,
TimeoutError = 3,
TeardownError = 4,
OutOfRange = 1,
ObjectUnsubscribed = 2,
Timeout = 3,
Teardown = 4,
}

/**
* Creates an error and decorates it with the appropriate error code for identification later.
*/
export function createRxError(message: string, code: RxErrorCode, ErrorType: any = Error) {
const result = new ErrorType('RxJS: ' + message);
(result as any).__rxjsErrorCode = code;
Expand All @@ -33,23 +39,23 @@ export function isEmptyError(err: any) {
* was out of range.
*/
export function isOutOfRangeError(err: any) {
return err.__rxjsErrorCode === RxErrorCode.OutOfRangeError;
return err.__rxjsErrorCode === RxErrorCode.OutOfRange;
}

/**
* Checks to see if the value passed is an error thrown by RxJS when a Subject
* was unsubscribed, and an action was taken on it.
*/
export function isObjectUnsubscribedError(err: any) {
return err.__rxjsErrorCode === RxErrorCode.ObjectUnsubscribedError;
return err.__rxjsErrorCode === RxErrorCode.ObjectUnsubscribed;
}

/**
* Checks to see if the value passed is an error thrown by RxJS when an observable
* times out, for example with the {@link timeout} operator.
*/
export function isTimeoutError(err: any) {
return err.__rxjsErrorCode === RxErrorCode.TimeoutError;
return err.__rxjsErrorCode === RxErrorCode.Timeout;
}

/**
Expand All @@ -58,5 +64,5 @@ export function isTimeoutError(err: any) {
* chain.
*/
export function isTeardownError(err: any) {
return err.__rxjsErrorCode === RxErrorCode.TeardownError;
return err.__rxjsErrorCode === RxErrorCode.Teardown;
}

0 comments on commit 4959bd5

Please sign in to comment.