mirror of
https://github.com/laurent22/joplin.git
synced 2025-03-23 21:09:30 +02:00
Desktop: Improved Joplin Server error handling
This commit is contained in:
parent
de7579a14e
commit
95d7ccccea
@ -766,9 +766,10 @@ export default class BaseApplication {
|
||||
}
|
||||
|
||||
if (Setting.value('env') === Env.Dev) {
|
||||
// Setting.setValue('sync.10.path', 'https://api.joplincloud.com');
|
||||
Setting.setValue('sync.10.path', 'http://api-joplincloud.local:22300');
|
||||
Setting.setValue('sync.10.userContentPath', 'http://joplinusercontent.local:22300');
|
||||
Setting.setValue('sync.10.path', 'https://api.joplincloud.com');
|
||||
Setting.setValue('sync.10.userContentPath', 'https://joplinusercontent.com');
|
||||
// Setting.setValue('sync.10.path', 'http://api-joplincloud.local:22300');
|
||||
// Setting.setValue('sync.10.userContentPath', 'http://joplinusercontent.local:22300');
|
||||
}
|
||||
|
||||
// For now always disable fuzzy search due to performance issues:
|
||||
|
@ -48,7 +48,7 @@ export default class JoplinServerApi {
|
||||
this.options_ = options;
|
||||
|
||||
if (options.env === Env.Dev) {
|
||||
this.debugRequests_ = true;
|
||||
// this.debugRequests_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -175,13 +175,16 @@ export default class JoplinServerApi {
|
||||
logger.debug('Response', Date.now() - startTime, options.responseFormat, responseText);
|
||||
}
|
||||
|
||||
const shortResponseText = () => {
|
||||
return (`${responseText}`).substr(0, 1024);
|
||||
};
|
||||
|
||||
// Creates an error object with as much data as possible as it will appear in the log, which will make debugging easier
|
||||
const newError = (message: string, code: number = 0) => {
|
||||
// Gives a shorter response for error messages. Useful for cases where a full HTML page is accidentally loaded instead of
|
||||
// JSON. That way the error message will still show there's a problem but without filling up the log or screen.
|
||||
const shortResponseText = (`${responseText}`).substr(0, 1024);
|
||||
// return new JoplinError(`${method} ${path}: ${message} (${code}): ${shortResponseText}`, code);
|
||||
return new JoplinError(message, code, `${method} ${path}: ${message} (${code}): ${shortResponseText}`);
|
||||
return new JoplinError(message, code, `${method} ${path}: ${message} (${code}): ${shortResponseText()}`);
|
||||
};
|
||||
|
||||
let responseJson_: any = null;
|
||||
@ -207,7 +210,21 @@ export default class JoplinServerApi {
|
||||
throw newError(`${json.error}`, json.code ? json.code : response.status);
|
||||
}
|
||||
|
||||
throw newError('Unknown error', response.status);
|
||||
// "Unknown error" means it probably wasn't generated by the
|
||||
// application but for example by the Nginx or Apache reverse
|
||||
// proxy. So in that case we attach the response content to the
|
||||
// error message so that it shows up in logs. It might be for
|
||||
// example an error returned by the Nginx or Apache reverse
|
||||
// proxy. For example:
|
||||
//
|
||||
// <html>
|
||||
// <head><title>413 Request Entity Too Large</title></head>
|
||||
// <body>
|
||||
// <center><h1>413 Request Entity Too Large</h1></center>
|
||||
// <hr><center>nginx/1.18.0 (Ubuntu)</center>
|
||||
// </body>
|
||||
// </html>
|
||||
throw newError(`Unknown error: ${shortResponseText()}`, response.status);
|
||||
}
|
||||
|
||||
if (options.responseFormat === 'text') return responseText;
|
||||
|
@ -41,11 +41,11 @@ export default class SyncTargetJoplinCloud extends BaseSyncTarget {
|
||||
public static async checkConfig(options: FileApiOptions) {
|
||||
return SyncTargetJoplinServer.checkConfig({
|
||||
...options,
|
||||
});
|
||||
}, SyncTargetJoplinCloud.id());
|
||||
}
|
||||
|
||||
protected async initFileApi() {
|
||||
return initFileApi(this.logger(), {
|
||||
return initFileApi(SyncTargetJoplinCloud.id(), this.logger(), {
|
||||
path: () => Setting.value('sync.10.path'),
|
||||
userContentPath: () => Setting.value('sync.10.userContentPath'),
|
||||
username: () => Setting.value('sync.10.username'),
|
||||
|
@ -31,8 +31,8 @@ export async function newFileApi(id: number, options: FileApiOptions) {
|
||||
return fileApi;
|
||||
}
|
||||
|
||||
export async function initFileApi(logger: Logger, options: FileApiOptions) {
|
||||
const fileApi = await newFileApi(SyncTargetJoplinServer.id(), options);
|
||||
export async function initFileApi(syncTargetId: number, logger: Logger, options: FileApiOptions) {
|
||||
const fileApi = await newFileApi(syncTargetId, options);
|
||||
fileApi.setLogger(logger);
|
||||
return fileApi;
|
||||
}
|
||||
@ -63,14 +63,16 @@ export default class SyncTargetJoplinServer extends BaseSyncTarget {
|
||||
return super.fileApi();
|
||||
}
|
||||
|
||||
public static async checkConfig(options: FileApiOptions) {
|
||||
public static async checkConfig(options: FileApiOptions, syncTargetId: number = null) {
|
||||
const output = {
|
||||
ok: false,
|
||||
errorMessage: '',
|
||||
};
|
||||
|
||||
syncTargetId = syncTargetId === null ? SyncTargetJoplinServer.id() : syncTargetId;
|
||||
|
||||
try {
|
||||
const fileApi = await newFileApi(SyncTargetJoplinServer.id(), options);
|
||||
const fileApi = await newFileApi(syncTargetId, options);
|
||||
fileApi.requestRepeatCount_ = 0;
|
||||
|
||||
await fileApi.put('testing.txt', 'testing');
|
||||
@ -87,7 +89,7 @@ export default class SyncTargetJoplinServer extends BaseSyncTarget {
|
||||
}
|
||||
|
||||
protected async initFileApi() {
|
||||
return initFileApi(this.logger(), {
|
||||
return initFileApi(SyncTargetJoplinServer.id(), this.logger(), {
|
||||
path: () => Setting.value('sync.9.path'),
|
||||
userContentPath: () => Setting.value('sync.9.userContentPath'),
|
||||
username: () => Setting.value('sync.9.username'),
|
||||
|
Loading…
x
Reference in New Issue
Block a user