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 11, 2019
1 parent 7f3d89e commit fabd617
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 21 deletions.
6 changes: 1 addition & 5 deletions src/internal/operators/elementAt.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
<<<<<<< HEAD
import { ArgumentOutOfRangeError } from '../util/ArgumentOutOfRangeError';
=======
import { createOutOfRangeError } from '../util/ArgumentOutOfRangeError';
>>>>>>> refactor(ArgumentOutOfRangeError): is now deprecated
import { Observable } from '../Observable';
import { MonoTypeOperatorFunction } from '../types';
import { filter } from './filter';
import { throwIfEmpty } from './throwIfEmpty';
import { defaultIfEmpty } from './defaultIfEmpty';
import { take } from './take';
import { take } from './take';s

/**
* Emits the single value at the specified `index` in a sequence of emissions
Expand Down
4 changes: 0 additions & 4 deletions src/internal/operators/last.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { Observable } from '../Observable';
<<<<<<< HEAD
import { EmptyError } from '../util/EmptyError';
=======
import { createEmptyError } from '../util/EmptyError';
>>>>>>> refactor(EmptyError): is deprecated
import { OperatorFunction } from '../../internal/types';
import { filter } from './filter';
import { takeLast } from './takeLast';
Expand Down
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 fabd617

Please sign in to comment.