@@ -20,7 +20,18 @@ const { NETLIFYDEV, NETLIFYDEVWARN, NETLIFYDEVERR } = require("../cli-logo");
20
20
async function addEnvVariables ( api , site , accessToken ) {
21
21
/** from addons */
22
22
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
+ } ) ;
24
35
if ( Array . isArray ( addons ) ) {
25
36
addons . forEach ( addon => {
26
37
addonUrls [ addon . slug ] = `${ addon . config . site_url } /.netlify/${ addon . slug } ` ;
@@ -36,7 +47,29 @@ async function addEnvVariables(api, site, accessToken) {
36
47
}
37
48
38
49
/** 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
+ } ) ;
40
73
// TODO: We should move the environment outside of build settings and possibly have a
41
74
// `/api/v1/sites/:site_id/environment` endpoint for it that we can also gate access to
42
75
// In the future and that we could make context dependend
0 commit comments