Skip to content

Bug : Redirect happens even when fetch fails #162

@SmartSankarCode

Description

@SmartSankarCode

Hello sir @SuperSimpleDev @spencer-lochne

I noticed that the code redirects to orders.html even if the fetch request fails.

This happens because window.location.href = 'orders.html'; is outside the try...catch, so it runs no matter what.

Maybe you could move the redirect inside the try block, so it only happens if the fetch is successful?

Example:

try {
const response = await fetch(...);
const order = await response.json();
addOrder(order);

window.location.href = 'orders.html'; // redirect after success
} catch (error) {
console.log('Unexpected error. Try again later.');
}

Just a small thing I noticed. Thanks for the cool project! @SuperSimpleDev

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions