atlassian / nucleus

A configurable and versatile update server for all your Electron apps
Other
398 stars 93 forks source link

Upload endpoint returns internal server error without error message #73

Closed gkrzysztof92 closed 5 years ago

gkrzysztof92 commented 5 years ago

I wrote a custom publisher based on @electron-forge/publisher-nucleus. Upload endpoint returns an internal server error without error body. Below is the publisher code.

How can I investigate this issue? Is Nucleus writes error logs?

const config = require('./nucleusConfiguration.json')
const packageJson = require('./package.json');
const fetch = require('node-fetch');
const fs = require('fs');
const path = require('path');
const FormData = require('form-data');

const releasePath = 'out/make/squirrel.windows/x64';

async function publish() {

    const form = new FormData();
    form.append('platform', 'win');
    form.append('arch', 'x64');
    form.append('version', packageJson.version);

    let artifactIdx = 0;
    fs.readdirSync(releasePath)
        .forEach(file => {
            if (file.toLowerCase() !== 'releases') {
                form.append(`file${artifactIdx}`,  fs.createReadStream(path.join(__dirname, releasePath, file)), file)
                artifactIdx += 1;
            }
        });

        const response = await fetch(
            `${config.nucleusHost}/rest/app/${config.appId}/channel/${config.channelId}/upload`,
            { 
                headers: { 
                    Authorization: config.token
                },
                timeout: 0,
                method: 'POST',
                body: form
            }
        );

        if (response.status !== 200) {
            throw new Error(`Unexpected response code from Nucleus: ${response.status}\n\nBody:\n${await response.text()}`);
        }

}

publish().then(() => console.log('Published!')).catch(err => console.log(err));

Output

Error: Unexpected response code from Nucleus: 500

Body:

    at publish (D:\electron-forge-app\nucleusPublisher.js:41:19)
    at processTicksAndRejections (internal/process/task_queues.js:86:5)
MarshallOfSound commented 5 years ago

@gkrzysztof92 If you set DEBUG=nucleus* when you run nucleus it will log the 500 errors to console

gkrzysztof92 commented 5 years ago
Thu, 18 Apr 2019 11:05:53 GMT nucleus An error occurred inside Nucleus: { error: 'Invalid platform provided' }

Changed platform from win to win32. 400 status code would be better for this error.

MarshallOfSound commented 5 years ago

@gkrzysztof92 PRs welcome 👍

https://github.com/atlassian/nucleus/blob/bb3c7492e42a845a091e3ca5878573f4efb2fc22/src/rest/app.ts#L527