Skip to content
This repository was archived by the owner on Sep 12, 2019. It is now read-only.

Commit 4a27baf

Browse files
author
sw-yx
committed
minor DX improvements for when siteID is not owned by user
1 parent a24c783 commit 4a27baf

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

src/utils/dev.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,18 @@ const { NETLIFYDEV, NETLIFYDEVWARN, NETLIFYDEVERR } = require("../cli-logo");
2020
async function addEnvVariables(api, site, accessToken) {
2121
/** from addons */
2222
const addonUrls = {};
23-
const addons = await getAddons(site.id, accessToken);
23+
const addons = await getAddons(site.id, accessToken).catch(err => {
24+
console.error(err);
25+
switch (err.status) {
26+
default:
27+
console.error(
28+
`${NETLIFYDEVERR} Error retrieving addons data for site ${chalk.yellow(
29+
site.id
30+
)}. Double-check your login status with 'netlify status' or contact support with details of your error.`
31+
);
32+
process.exit();
33+
}
34+
});
2435
if (Array.isArray(addons)) {
2536
addons.forEach(addon => {
2637
addonUrls[addon.slug] = `${addon.config.site_url}/.netlify/${addon.slug}`;
@@ -36,7 +47,29 @@ async function addEnvVariables(api, site, accessToken) {
3647
}
3748

3849
/** from web UI */
39-
const apiSite = await api.getSite({ site_id: site.id });
50+
const apiSite = await api.getSite({ site_id: site.id }).catch(err => {
51+
console.error(err);
52+
switch (err.status) {
53+
case 401:
54+
console.error(
55+
`${NETLIFYDEVERR} Unauthorized error: This Site ID ${chalk.yellow(
56+
site.id
57+
)} does not belong to your account.`
58+
);
59+
console.error(
60+
`${NETLIFYDEVERR} If you cloned someone else's code, try running 'npm unlink' and then 'npm init' or 'npm link'.`
61+
);
62+
63+
process.exit();
64+
default:
65+
console.error(
66+
`${NETLIFYDEVERR} Error retrieving site data for site ${chalk.yellow(
67+
site.id
68+
)}. Double-check your login status with 'netlify status' or contact support with details of your error.`
69+
);
70+
process.exit();
71+
}
72+
});
4073
// TODO: We should move the environment outside of build settings and possibly have a
4174
// `/api/v1/sites/:site_id/environment` endpoint for it that we can also gate access to
4275
// In the future and that we could make context dependend

0 commit comments

Comments
 (0)