Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor remove error downlevel workaround #7262

Merged
27 changes: 0 additions & 27 deletions spec/util/createErrorClass-spec.ts

This file was deleted.

76 changes: 27 additions & 49 deletions src/internal/ajax/errors.ts
@@ -1,76 +1,53 @@
import { AjaxRequest } from './types';
import { createErrorClass } from '../util/createErrorClass';

/**
* A normalized AJAX error.
* Thrown when an error occurs during an AJAX request.
* This is only exported because it is useful for checking to see if an error
* is an `instanceof AjaxError`. DO NOT create new instances of `AjaxError` with
* the constructor.
*
* @see {@link ajax}
*/
export interface AjaxError extends Error {
export class AjaxError extends Error {
/**
* The XHR instance associated with the error.
*/
xhr: XMLHttpRequest;
readonly xhr: XMLHttpRequest;

/**
* The AjaxRequest associated with the error.
*/
request: AjaxRequest;
readonly request: AjaxRequest;

/**
* The HTTP status code, if the request has completed. If not,
* it is set to `0`.
*/
status: number;
readonly status: number;

/**
* The responseType (e.g. 'json', 'arraybuffer', or 'xml').
*/
responseType: XMLHttpRequestResponseType;
readonly responseType: XMLHttpRequestResponseType;

/**
* The response data.
*/
response: any;
}
readonly response: any;

export interface AjaxErrorCtor {
/**
* @deprecated Internal implementation detail. Do not construct error instances.
* Cannot be tagged as internal: https://github.com/ReactiveX/rxjs/issues/6269
*/
new (message: string, xhr: XMLHttpRequest, request: AjaxRequest): AjaxError;
}

/**
* Thrown when an error occurs during an AJAX request.
* This is only exported because it is useful for checking to see if an error
* is an `instanceof AjaxError`. DO NOT create new instances of `AjaxError` with
* the constructor.
*
* @see {@link ajax}
*/
export const AjaxError: AjaxErrorCtor = createErrorClass(
(_super) =>
function AjaxErrorImpl(this: any, message: string, xhr: XMLHttpRequest, request: AjaxRequest) {
this.message = message;
this.name = 'AjaxError';
this.xhr = xhr;
this.request = request;
this.status = xhr.status;
this.responseType = xhr.responseType;
this.response = xhr.response;
}
);

export interface AjaxTimeoutError extends AjaxError {}

export interface AjaxTimeoutErrorCtor {
/**
* @deprecated Internal implementation detail. Do not construct error instances.
* Cannot be tagged as internal: https://github.com/ReactiveX/rxjs/issues/6269
*/
new (xhr: XMLHttpRequest, request: AjaxRequest): AjaxTimeoutError;
constructor(message: string, xhr: XMLHttpRequest, request: AjaxRequest) {
super(message);
this.name = 'AjaxError';
this.xhr = xhr;
this.request = request;
this.status = xhr.status;
this.responseType = xhr.responseType;
this.response = xhr.response;
}
}

/**
Expand All @@ -82,12 +59,13 @@ export interface AjaxTimeoutErrorCtor {
*
* @see {@link ajax}
*/
export const AjaxTimeoutError: AjaxTimeoutErrorCtor = (() => {
function AjaxTimeoutErrorImpl(this: any, xhr: XMLHttpRequest, request: AjaxRequest) {
AjaxError.call(this, 'ajax timeout', xhr, request);
export class AjaxTimeoutError extends AjaxError {
/**
* @deprecated Internal implementation detail. Do not construct error instances.
* Cannot be tagged as internal: https://github.com/ReactiveX/rxjs/issues/6269
*/
constructor(xhr: XMLHttpRequest, request: AjaxRequest) {
super('ajax timeout', xhr, request);
this.name = 'AjaxTimeoutError';
return this;
}
AjaxTimeoutErrorImpl.prototype = Object.create(AjaxError.prototype);
return AjaxTimeoutErrorImpl;
})() as any;
}
47 changes: 15 additions & 32 deletions src/internal/operators/timeout.ts
Expand Up @@ -4,7 +4,6 @@ import { isValidDate } from '../util/isDate';
import { Subscription } from '../Subscription';
import { Observable } from '../Observable';
import { from } from '../observable/from';
import { createErrorClass } from '../util/createErrorClass';
import { createOperatorSubscriber } from './OperatorSubscriber';
import { executeSchedule } from '../util/executeSchedule';

Expand Down Expand Up @@ -50,28 +49,6 @@ export interface TimeoutInfo<T, M = unknown> {
readonly lastValue: T | null;
}

/**
* An error emitted when a timeout occurs.
*/
export interface TimeoutError<T = unknown, M = unknown> extends Error {
/**
* The information provided to the error by the timeout
* operation that created the error. Will be `null` if
* used directly in non-RxJS code with an empty constructor.
* (Note that using this constructor directly is not recommended,
* you should create your own errors)
*/
info: TimeoutInfo<T, M> | null;
}

export interface TimeoutErrorCtor {
/**
* @deprecated Internal implementation detail. Do not construct error instances.
* Cannot be tagged as internal: https://github.com/ReactiveX/rxjs/issues/6269
*/
new <T = unknown, M = unknown>(info?: TimeoutInfo<T, M>): TimeoutError<T, M>;
}

/**
* An error thrown by the {@link timeout} operator.
*
Expand All @@ -82,15 +59,21 @@ export interface TimeoutErrorCtor {
*
* @see {@link timeout}
*/
export const TimeoutError: TimeoutErrorCtor = createErrorClass(
(_super) =>
function TimeoutErrorImpl(this: any, info: TimeoutInfo<any> | null = null) {
_super(this);
this.message = 'Timeout has occurred';
this.name = 'TimeoutError';
this.info = info;
}
);
export class TimeoutError<T, M> extends Error {
/**
* @param info The information provided to the error by the timeout
* operation that created the error. Will be `null` if
* used directly in non-RxJS code with an empty constructor.
* (Note that using this constructor directly is not recommended,
* you should create your own errors)
* @deprecated Internal implementation detail. Do not construct error instances.
* Cannot be tagged as internal: https://github.com/ReactiveX/rxjs/issues/6269
*/
constructor(public info: TimeoutInfo<T, M> | null = null) {
super('Timeout has occurred');
this.name = 'TimeoutError';
}
}

/**
* If `with` is provided, this will return an observable that will switch to a different observable if the source
Expand Down
30 changes: 10 additions & 20 deletions src/internal/util/ArgumentOutOfRangeError.ts
@@ -1,15 +1,3 @@
import { createErrorClass } from './createErrorClass';

export interface ArgumentOutOfRangeError extends Error {}

export interface ArgumentOutOfRangeErrorCtor {
/**
* @deprecated Internal implementation detail. Do not construct error instances.
* Cannot be tagged as internal: https://github.com/ReactiveX/rxjs/issues/6269
*/
new (): ArgumentOutOfRangeError;
}

/**
* An error thrown when an element was queried at a certain index of an
* Observable, but no such index or position exists in that sequence.
Expand All @@ -18,11 +6,13 @@ export interface ArgumentOutOfRangeErrorCtor {
* @see {@link take}
* @see {@link takeLast}
*/
export const ArgumentOutOfRangeError: ArgumentOutOfRangeErrorCtor = createErrorClass(
(_super) =>
function ArgumentOutOfRangeErrorImpl(this: any) {
_super(this);
this.name = 'ArgumentOutOfRangeError';
this.message = 'argument out of range';
}
);
export class ArgumentOutOfRangeError extends Error {
/**
* @deprecated Internal implementation detail. Do not construct error instances.
* Cannot be tagged as internal: https://github.com/ReactiveX/rxjs/issues/6269
*/
constructor() {
super('argument out of range');
this.name = 'ArgumentOutOfRangeError';
}
}
30 changes: 10 additions & 20 deletions src/internal/util/EmptyError.ts
@@ -1,15 +1,3 @@
import { createErrorClass } from './createErrorClass';

export interface EmptyError extends Error {}

export interface EmptyErrorCtor {
/**
* @deprecated Internal implementation detail. Do not construct error instances.
* Cannot be tagged as internal: https://github.com/ReactiveX/rxjs/issues/6269
*/
new (): EmptyError;
}

/**
* An error thrown when an Observable or a sequence was queried but has no
* elements.
Expand All @@ -20,11 +8,13 @@ export interface EmptyErrorCtor {
* @see {@link firstValueFrom}
* @see {@link lastValueFrom}
*/
export const EmptyError: EmptyErrorCtor = createErrorClass(
(_super) =>
function EmptyErrorImpl(this: any) {
_super(this);
this.name = 'EmptyError';
this.message = 'no elements in sequence';
}
);
export class EmptyError extends Error {
/**
* @deprecated Internal implementation detail. Do not construct error instances.
* Cannot be tagged as internal: https://github.com/ReactiveX/rxjs/issues/6269
*/
constructor() {
super('no elements in sequence');
this.name = 'EmptyError';
}
}
30 changes: 10 additions & 20 deletions src/internal/util/NotFoundError.ts
@@ -1,26 +1,16 @@
import { createErrorClass } from './createErrorClass';

export interface NotFoundError extends Error {}

export interface NotFoundErrorCtor {
/**
* @deprecated Internal implementation detail. Do not construct error instances.
* Cannot be tagged as internal: https://github.com/ReactiveX/rxjs/issues/6269
*/
new (message: string): NotFoundError;
}

/**
* An error thrown when a value or values are missing from an
* observable sequence.
*
* @see {@link operators/single}
*/
export const NotFoundError: NotFoundErrorCtor = createErrorClass(
(_super) =>
function NotFoundErrorImpl(this: any, message: string) {
_super(this);
this.name = 'NotFoundError';
this.message = message;
}
);
export class NotFoundError extends Error {
/**
* @deprecated Internal implementation detail. Do not construct error instances.
* Cannot be tagged as internal: https://github.com/ReactiveX/rxjs/issues/6269
*/
constructor(message: string) {
super(message);
this.name = 'NotFoundError';
}
}
30 changes: 10 additions & 20 deletions src/internal/util/SequenceError.ts
@@ -1,26 +1,16 @@
import { createErrorClass } from './createErrorClass';

export interface SequenceError extends Error {}

export interface SequenceErrorCtor {
/**
* @deprecated Internal implementation detail. Do not construct error instances.
* Cannot be tagged as internal: https://github.com/ReactiveX/rxjs/issues/6269
*/
new (message: string): SequenceError;
}

/**
* An error thrown when something is wrong with the sequence of
* values arriving on the observable.
*
* @see {@link operators/single}
*/
export const SequenceError: SequenceErrorCtor = createErrorClass(
(_super) =>
function SequenceErrorImpl(this: any, message: string) {
_super(this);
this.name = 'SequenceError';
this.message = message;
}
);
export class SequenceError extends Error {
/**
* @deprecated Internal implementation detail. Do not construct error instances.
* Cannot be tagged as internal: https://github.com/ReactiveX/rxjs/issues/6269
*/
constructor(message: string) {
super(message);
this.name = 'SequenceError';
}
}