Signal an asynchronous failure
Return a rejected promise from a function when validation or preconditions fail.
JavaScript · Function
Promise.reject() creates and returns a new promise that is already rejected with the supplied reason. It is useful for producing rejection branches or adapting a value into a rejected promise.
Promise.reject(reason) creates an already-rejected promise whose rejection reason is the supplied value. It always creates a new Promise, can be used with Promise subclasses, and is equivalent in effect to constructing a promise whose executor calls reject(reason).
Promise.reject(reason)| Name | Type | Description |
|---|---|---|
reason | any | Reason why this Promise rejected. |
A Promise that is rejected with the given reason.
Promise.reject(new Error("Request failed"))
.catch((error) => console.error(error.message));Creates an immediately rejected promise and handles its reason with catch().
Return a rejected promise from a function when validation or preconditions fail.
Create predictable failure inputs for promise-chain or async-handler tests.
Convert a synchronous error value into a rejected promise for a uniform async API.
PromisePromise.resolve()Promise.prototype.catch()Promise.prototype.then()