Fixing “Uncaught (in promise)” in JavaScript
When you fetch data from an API, the browser console may show a red error starting with Uncaught (in promise). This message appears when a await or then operation fails and nothing catches the failure. If you catch the failure with try…catch or .catch(), this line goes away.
I reproduced this error in my test environment and copied the text from the DevTools Console panel exactly as it appeared. I then confirmed that adding a catch makes the message disappear, and that some ways of adding a catch do not make it disappear.
The test environment was Ubuntu 24.04, Node.js 22.23.4, and Chromium 153 (headless) launched with Playwright 1.63.0. I opened the page from a local HTTP server (127.0.0.1:8000). The Console panel text was taken from the DevTools UI bundled with the same Chromium, attached to the test page. I did not test Firefox or Safari.
If you don't catch an await failure, you get the error
The following main.js fetches user information from /api/user.json and displays the name in <p id="name">. In the test, I did not place /api/user.json, so the server returned 404.
async function loadUser() {
const res = await fetch("/api/user.json");
if (!res.ok) {
throw new Error(`ユーザー情報を読み込めませんでした(${res.status})`);
}
return res.json();
}
async function showUser() {
const user = await loadUser();
document.getElementById("name").textContent = user.name;
}
showUser();
When I opened the page, the DevTools Console panel showed these two messages:
GET http://127.0.0.1:8000/api/user.json 404 (File not found)
Uncaught (in promise) Error: ユーザー情報を読み込めませんでした(404)
at loadUser (main.js:4:11)
at async showUser (main.js:10:16)

The first line is the browser's record of the 404 response. The second line, Uncaught (in promise), means that an error thrown inside a Promise was not caught anywhere. It is followed by the thrown error (Error: ユーザー情報を読み込めませんでした(404), which means "Failed to load user information (404)") and the location where the error occurred. main.js:4:11 points to the throw on line 4 of main.js.
Because the error stopped showUser, the screen stayed at "Loading…".
Why "in promise" appears
If an error is thrown inside an async function and not caught within that function, the function's returned Promise is rejected (MDN: async function (English)). When an awaited Promise rejects, the await expression throws the same reason again (MDN: await (English)). In the example above, the failure in loadUser propagated to showUser, so the Promise returned by showUser() also rejected.
If a rejected Promise has no handler attached with then(), catch(), or finally() to receive the failure, the browser fires an unhandledrejection event (MDN: Promise.prototype.catch() (English)). If nothing calls preventDefault() on this event, the browser finally logs the error to the console (MDN: unhandledrejection event (English)). This is the Uncaught (in promise) line.
Note that fetch() does not reject for a response such as 404. It resolves with a Response as a success (MDN: fetch() (English)). In the example above, the failure happened because the code checked res.ok and threw the error itself.
The same message appeared when I used then chaining:
fetch("/api/user.json")
.then((res) => {
if (!res.ok) {
throw new Error(`ユーザー情報を読み込めませんでした(${res.status})`);
}
return res.json();
})
.then((user) => {
document.getElementById("name").textContent = user.name;
});
Uncaught (in promise) Error: ユーザー情報を読み込めませんでした(404)
at main.js:4:13
The function passed to then has no name, so the location was shown as main.js:4:13 without a function name.
Adding a catch removes the error
If you create a place that handles the failure, Uncaught (in promise) no longer appears. I tried the following three approaches. In each case this line disappeared and the error message was shown on the screen.
Wrap await in try…catch
Inside an async function, you can wrap await in an ordinary try…catch.
async function showUser() {
- const user = await loadUser();
- document.getElementById("name").textContent = user.name;
+ try {
+ const user = await loadUser();
+ document.getElementById("name").textContent = user.name;
+ } catch (err) {
+ document.getElementById("name").textContent = err.message;
+ }
}
Add .catch() at the end of the then chain
If you chain with then, add .catch() at the end. In my test, a failure thrown in the first then also reached the final .catch().
.then((user) => {
document.getElementById("name").textContent = user.name;
- });
+ })
+ .catch((err) => {
+ document.getElementById("name").textContent = err.message;
+ });
Add .catch() at the call site
You can also leave showUser unchanged and add .catch() where it is called. An async function returns a Promise, so .catch() can be attached to it.
-showUser();
+showUser().catch((err) => {
+ document.getElementById("name").textContent = err.message;
+});
The Console panel when I opened the page with this approach showed the following:
GET http://127.0.0.1:8000/api/user.json 404 (File not found)

The Uncaught (in promise) line was gone, but the 404 line remained. This line is the browser's record of the 404 response, and adding a catch does not remove it.
Even when the Uncaught (in promise) line disappears, the data still has not been loaded. Inside catch, write what the user should see when the failure happens, such as showing an error message on the screen or displaying a reload button.
If you call console.error(err) inside catch, the console shows the error's content and location. In the output I received through the DevTools Protocol, the line did not start with Uncaught (in promise); it started with Error: ユーザー情報を読み込めませんでした(404). This keeps the information needed to investigate the cause, and the error is recorded as a caught error.
Wrapping in try does not catch the error without await
Wrapping the call site in try…catch does not fix the problem if you call the function without await. When I wrote it like this, the same error appeared:
try {
showUser();
} catch (err) {
document.getElementById("name").textContent = err.message;
}
Uncaught (in promise) Error: ユーザー情報を読み込めませんでした(404)
at loadUser (main.js:4:11)
at async showUser (main.js:10:16)
When showUser() is called, it returns a Promise immediately. At that point the fetch has not finished, so nothing is thrown inside the try block. The failure becomes known only after the try…catch has been exited, so this catch never receives it. Either write await showUser() inside an async function, or attach .catch() as shown above.
Passing a string to reject gives no location
When you create a Promise yourself with new Promise, what you pass to reject changes how the message appears. The following wait fails with a string message (meaning "timed out") after the specified time has passed.
function wait(ms) {
return new Promise((resolve, reject) => {
setTimeout(() => reject("タイムアウトしました"), ms);
});
}
async function showUser() {
await wait(100);
document.getElementById("name").textContent = "表示しました";
}
showUser();
The Console panel showed only one line, with no location:
Uncaught (in promise) タイムアウトしました
After I changed reject("タイムアウトしました") to reject(new Error("タイムアウトしました")), the error type and location appeared:
Uncaught (in promise) Error: タイムアウトしました
at main.js:3:29
main.js:3:29 points to line 3, where new Error was created. The MDN page for Promise.reject() (English) notes that using an Error as the rejection reason helps debugging. The throw page (English) also recommends throwing an Error, because code that catches the value can read properties such as message.
Record missed failures with unhandledrejection
To find places where a catch was forgotten, you can listen for the unhandledrejection event across the whole page. I added the following code to the top of the first main.js (the version without a catch).
window.addEventListener("unhandledrejection", (event) => {
console.warn("catch されなかった失敗:", event.reason.message);
});
event.reason holds the reason for the failure (here, the Error that was thrown). When I opened the page, the warning (the text of the console.warn message, meaning "Uncaught failure: Failed to load user information (404)") appeared, and the Uncaught (in promise) line was still printed as well.
When I called event.preventDefault() inside this function, the Uncaught (in promise) line no longer appeared. The MDN unhandledrejection page (English) also says that calling preventDefault() stops the output to the console.
preventDefault() only removes the console message. In my test the screen still showed "Loading…", so the failure itself was not fixed. Use unhandledrejection to find missing catch calls, and write the behavior for each failure in that operation's own catch.





