== Why is this an issue?

The use of literals (primitive values such as strings, numbers, booleans, etc.) for promise rejection is generally discouraged. While it is syntactically valid to provide literals as a rejected promise value, it is considered best practice to use instances of the Error class or its subclasses instead.

Using an instance of the Error class allows you to provide more meaningful information about the error. The Error class and its subclasses provide properties such as message and stack that can be used to convey useful details about the error, such as a description of the problem, the context in which it occurred, or a stack trace for debugging.

[source,text,diff-id=1,diff-type=noncompliant]
----
new Promise(function(resolve, reject) {
  reject(); // Noncompliant: use Error object to provide rejection reason
});

new Promise(function(resolve, reject) {
  reject('Something went wrong'); // Noncompliant: use Error object instead of literal
});
----

To fix your code provide an instanse of the Error class to the promise reject function.

[source,text,diff-id=1,diff-type=compliant]
----
new Promise(function(resolve, reject) {
  reject(new Error('Network timeout'));
});

new Promise(function(resolve, reject) {
  reject(new Error('Something went wrong'));
});
----

== Resources
=== Documentation
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise[MDN - Promise]
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error[MDN - Error]
=== Related rules
 * S3696

ifdef::env-github,rspecator-view[]

'''
== Comments And Links
(visible only on this page)

=== relates to: S3696

endif::env-github,rspecator-view[]
