sitevision / sitevision-apps

Create SiteVision WebApps and RESTApps
15 stars 17 forks source link

Upload failed, status code: SyntaxError: Unexpected token < in JSON at position 0 #109

Closed emtiazzahid closed 1 year ago

emtiazzahid commented 1 year ago

After running dev its showing that error. here are the log

λ npm run dev

> sitevision-app@0.0.1 dev
> sitevision-scripts dev

[nodemon] 2.0.22
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): src\**\*
[nodemon] watching extensions: js,html,css,less,json
[nodemon] starting `node C:\laragon\www\sitevision-app\node_modules\@sitevision\sitevision-scripts\bin\sitevision-scripts.js build force-deploy`
Successfully compiled 3 files with Babel (724ms).
Compression successful
Upload failed, status code: SyntaxError: Unexpected token < in JSON at position 0
[nodemon] clean exit - waiting for changes before restart

node -v : v18.12.1 npm -v: 9.8.0

can anyone help please

magloven commented 1 year ago

"Unexpected token < in JSON at position 0" typically indicates that the response is in html format. The first that comes to mind is that the error page of the site might be returned. This could be the case for a bad request (bad domain, bad data) or a request that lacks permission to perform what the endpoint is supposed to do.

emtiazzahid commented 1 year ago

Thanks for your reply. I think its related with dev_properties data I have here are the sample format I using. note: I have changed the characters for safety.

{
  "domain": "use-opreno.sitevision-cloud.se",
  "siteName": "my site",
  "addonName": "mysiteaddon",
  "username": "test@test.no",
  "password": "eAl-Gfpse1GTFL"
}

and after I changed the username "test" for test purpose the error is changed to Upload failed, status code: SyntaxError: Unexpected end of JSON input

npm run create-addon mysiteaddon also gives same error Addon creation failed:, SyntaxError: Unexpected end of JSON input

emtiazzahid commented 1 year ago

thanks @magloven . I had two problems and found that the issue was in siteName and permission issues. if we can catch the response error so we may get the more meaningful responses we get example here i added a catch in the fetch method

    const response = await fetch(url, {
      method: 'post',
      body: JSON.stringify({ name: props.addonName, category: 'Other' }),
      headers: {
        Authorization: `Basic ${Buffer.from(
          props.username + ':' + props.password
        ).toString('base64')}`,
      },
    }).catch(error => {
        console.error(`${chalk.red('Error:')}, ${error}`);
    });

that gave me that error response

{
  "success": false,
  "type": "invalidParameter",
  "description": "An invalid parameter (query or request body) was specified",
  "message": "BAD_REQUEST: Unable to process /rest-api/1/0/mySiteName/Addon%20Repository/custommodule, could not resolve context node"
}

so I found that the issue was in my site name