Skip to content

Commit

Permalink
All: Fixes #491: Handle non-standard ports and better handling of fet…
Browse files Browse the repository at this point in the history
…chBlob errors
  • Loading branch information
laurent22 committed May 20, 2018
1 parent 43bab3c commit 04724c5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ReactNativeClient/lib/models/Setting.js
Expand Up @@ -100,7 +100,7 @@ class Setting extends BaseModel {
'encryption.activeMasterKeyId': { value: '', type: Setting.TYPE_STRING, public: false },
'encryption.passwordCache': { value: {}, type: Setting.TYPE_OBJECT, public: false },
'style.zoom': {value: "100", type: Setting.TYPE_INT, public: true, appTypes: ['desktop'], label: () => _('Global zoom percentage'), minimum: "50", maximum: "500", step: "10"},
'style.editor.fontFamily': {value: "", type: Setting.TYPE_STRING, public: true, appTypes: ['desktop'], label: () => _('Editor font family'), description: () => _('The font name will not be checked. If incorrect or empty, it will default to a generic monospace font.')},
'style.editor.fontFamily': {value: "", type: Setting.TYPE_STRING, public: true, appTypes: ['desktop'], label: () => _('Editor font family'), description: () => _('This must be *monospace* font or it will not work properly. If the font is incorrect or empty, it will default to a generic monospace font.')},
'autoUpdateEnabled': { value: true, type: Setting.TYPE_BOOL, public: true, appTypes: ['desktop'], label: () => _('Automatically update the application') },
'sync.interval': { value: 300, type: Setting.TYPE_INT, isEnum: true, public: true, label: () => _('Synchronisation interval'), options: () => {
return {
Expand Down
32 changes: 25 additions & 7 deletions ReactNativeClient/lib/shim-init-node.js
Expand Up @@ -184,7 +184,7 @@ function shimInit() {

const requestOptions = {
protocol: url.protocol,
host: url.host,
host: url.hostname,
port: url.port,
method: method,
path: url.path + (url.query ? '?' + url.query : ''),
Expand All @@ -193,9 +193,29 @@ function shimInit() {

const doFetchOperation = async () => {
return new Promise((resolve, reject) => {
let file = null;

const cleanUpOnError = (error) => {
// We ignore any unlink error as we only want to report on the main error
fs.unlink(filePath).catch(() => {}).then(() => {
if (file) {
file.close(() => {
file = null;
reject(error);
});
} else {
reject(error);
}
});
}

try {
// Note: relative paths aren't supported
const file = fs.createWriteStream(filePath);
file = fs.createWriteStream(filePath);

file.on('error', function(error) {
cleanUpOnError(error);
});

const request = http.request(requestOptions, function(response) {
response.pipe(file);
Expand All @@ -208,14 +228,12 @@ function shimInit() {
})

request.on('error', function(error) {
fs.unlink(filePath);
reject(error);
cleanUpOnError(error);
});

request.end();
} catch(error) {
fs.unlink(filePath);
reject(error);
} catch (error) {
cleanUpOnError(error);
}
});
};
Expand Down

0 comments on commit 04724c5

Please sign in to comment.