Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: error codes for the getLatest function #218

Open
thoro23 opened this issue Jun 22, 2023 · 3 comments
Open

feat: error codes for the getLatest function #218

thoro23 opened this issue Jun 22, 2023 · 3 comments

Comments

@thoro23
Copy link

thoro23 commented Jun 22, 2023

Feature Request

Description

getLatest throws an error if no new version exists. To distinguish between a "real" error only the message can be used. So this is what I currently do:

try {
    newVersionBundle = await CapacitorUpdater.getLatest();
} catch (e) {
    // bail out if no new version is available
    if (e.message === 'No new version available') {
        return;
    }

    me.sendUpdateFailMetric(`Retrieving the new version info failed: ${e.message}`);
    return;
}

But checking against a message string that might change any time if very fragile.

Preferred Solution

The preferred solution would be another function like checkForUpdates that returns true if a new update is available. Or that the errors returned by getLatest will have a status code which I can check against.

@riderx
Copy link
Collaborator

riderx commented Jul 6, 2023

understand your concern, i'm not sure about spliting in 2 maybe adding error code ? could help what do you think ?

@thoro23
Copy link
Author

thoro23 commented Jul 6, 2023

getLatest implies that simply the latest update is retrieved and not that it is checked against the current version. Making it clearer in the docs that this method uses the installed version to check if a new version is available will be a huge help.
Also I think the error codes would not be needed if the promise would simly not reject. The promise should only reject if something failed, that no new version is available is no reason to reject the promise. To indicate that no new version is available a flag noNewVersion could be used.
I you dont agree an error code would also be sufficient.

@alexcroox
Copy link

Note this is a breaking change from older versions. It used to allow you to return just a "message" key from the server and would mark it as no updates required if no url/version key.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants