1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Desktop: Displays error info when Joplin Server fails

This commit is contained in:
Laurent Cozic 2021-05-21 17:42:32 +02:00
parent e94503abbe
commit 3f0586ef63

View File

@ -3,8 +3,11 @@ import { _ } from './locale';
const { rtrimSlashes } = require('./path-utils.js');
import JoplinError from './JoplinError';
import { Env } from './models/Setting';
import Logger from './Logger';
const { stringify } = require('query-string');
const logger = Logger.create('JoplinServerApi');
interface Options {
baseUrl(): string;
username(): string;
@ -133,13 +136,13 @@ export default class JoplinServerApi {
url += stringify(query);
}
let response: any = null;
try {
if (this.debugRequests_) {
console.info('Joplin API Call', `${method} ${url}`, headers, options);
console.info(this.requestToCurl_(url, fetchOptions));
logger.debug(this.requestToCurl_(url, fetchOptions));
}
let response: any = null;
if (options.source == 'file' && (method == 'POST' || method == 'PUT')) {
if (fetchOptions.path) {
const fileStat = await shim.fsDriver().stat(fetchOptions.path);
@ -157,7 +160,7 @@ export default class JoplinServerApi {
const responseText = await response.text();
if (this.debugRequests_) {
console.info('Joplin API Response', responseText);
logger.debug('Response', responseText);
}
// Creates an error object with as much data as possible as it will appear in the log, which will make debugging easier
@ -199,5 +202,12 @@ export default class JoplinServerApi {
const output = await loadResponseJson();
return output;
} catch (error) {
if (error.code !== 404) {
logger.warn(this.requestToCurl_(url, fetchOptions));
logger.warn(error);
}
throw error;
}
}
}