10 examples of 'uncaught (in promise)' in JavaScript

Every line of 'uncaught (in promise)' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
19export function handlePromiseRejection(promise) {
20 return promise.then(null, () => { /* swallow */ });
21}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

602function Rejected(x) {
603 Promise.createContext(this);
604
605 this.id = ++errorId;
606 this.value = x;
607 this.handled = false;
608 this.reported = false;
609
610 this._report();
611}
92function rejectPromise(e) {
93 return reject(e);
94}
230value: function handleUncaught(err) {
231 return _promise2.default.reject(err);
232}
120function unhandledRejectionFn(reason, promise) {
121 unhandled.push({ reason, promise });
122}
219function promiseReject (reason) {
220 self._handler.reject(reason);
221}
143export function defaultPossiblyUnhandledRejectionHandler(promise: Promise<any>): void {
144 let log = true;
145
146 // First try to emit Node event
147 if (typeof process !== "undefined" && typeof process.emit === "function") {
148 // Have to cast promise to any, because current typings of process.emit() have specific
149 // typings for arguments to "unhandledRejection", which say promise must be a Promise,
150 // but that Promise is the built-in type.
151 if (process.emit("unhandledRejection", promise.reason(), promise as any)) {
152 // A handler was called
153 log = false;
154 }
155 } else if (typeof PromiseRejectionEvent === "function") {
156 // Then fire a browser event if supported by the browser
157 if (emitRejectionEvent("unhandledrejection", promise.reason(), promise)) {
158 log = false;
159 }
160 }
161
162 // Fallback to log to console
163 if (log) {
164 const possiblyUnhandledRejection = new PossiblyUnhandledRejection(promise);
165 // tslint:disable-next-line:no-console
166 console.warn(possiblyUnhandledRejection.stack);
167 }
168}
45public sendUnhandledPromise(reason: any, promise: any): void {
46 const hub = getCurrentHub();
47
48 if (!hub.getIntegration(OnUnhandledRejection)) {
49 this._handleRejection(reason);
50 return;
51 }
52
53 const context = (promise.domain && promise.domain.sentryContext) || {};
54
55 hub.withScope((scope: Scope) => {
56 scope.setExtra('unhandledPromiseRejection', true);
57
58 // Preserve backwards compatibility with raven-node for now
59 if (context.user) {
60 scope.setUser(context.user);
61 }
62 if (context.tags) {
63 scope.setTags(context.tags);
64 }
65 if (context.extra) {
66 scope.setExtras(context.extra);
67 }
68
69 hub.captureException(reason, { originalException: promise });
70 });
71
72 this._handleRejection(reason);
73}
64public catch(onrejected: (reason: any) => (PromiseLike<any>|any)): Promise<any> {
65 return this.promise.catch(onrejected);
66}
23return function promiseRejection(error: any) {
24 let wrapped_error = new WrappedError(message, error);
25 if (log) {
26 console.error(wrapped_error);
27 }
28 return Promise.reject(wrapped_error);
29};

Related snippets