mirror of
https://github.com/laurent22/joplin.git
synced 2025-02-01 19:15:01 +02:00
Desktop: API: Improved error handling on service end-point
This commit is contained in:
parent
07720ed6f8
commit
d27b658392
@ -115,6 +115,7 @@ ReactNativeClient/lib/services/keychain/KeychainServiceDriver.node.js
|
|||||||
ReactNativeClient/lib/services/keychain/KeychainServiceDriverBase.js
|
ReactNativeClient/lib/services/keychain/KeychainServiceDriverBase.js
|
||||||
ReactNativeClient/lib/services/ResourceEditWatcher.js
|
ReactNativeClient/lib/services/ResourceEditWatcher.js
|
||||||
ReactNativeClient/lib/services/rest/actionApi.desktop.js
|
ReactNativeClient/lib/services/rest/actionApi.desktop.js
|
||||||
|
ReactNativeClient/lib/services/rest/errors.js
|
||||||
ReactNativeClient/lib/services/SettingUtils.js
|
ReactNativeClient/lib/services/SettingUtils.js
|
||||||
ReactNativeClient/lib/services/UndoRedoService.js
|
ReactNativeClient/lib/services/UndoRedoService.js
|
||||||
ReactNativeClient/lib/ShareExtension.js
|
ReactNativeClient/lib/ShareExtension.js
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -105,6 +105,7 @@ ReactNativeClient/lib/services/keychain/KeychainServiceDriver.node.js
|
|||||||
ReactNativeClient/lib/services/keychain/KeychainServiceDriverBase.js
|
ReactNativeClient/lib/services/keychain/KeychainServiceDriverBase.js
|
||||||
ReactNativeClient/lib/services/ResourceEditWatcher.js
|
ReactNativeClient/lib/services/ResourceEditWatcher.js
|
||||||
ReactNativeClient/lib/services/rest/actionApi.desktop.js
|
ReactNativeClient/lib/services/rest/actionApi.desktop.js
|
||||||
|
ReactNativeClient/lib/services/rest/errors.js
|
||||||
ReactNativeClient/lib/services/SettingUtils.js
|
ReactNativeClient/lib/services/SettingUtils.js
|
||||||
ReactNativeClient/lib/services/UndoRedoService.js
|
ReactNativeClient/lib/services/UndoRedoService.js
|
||||||
ReactNativeClient/lib/ShareExtension.js
|
ReactNativeClient/lib/ShareExtension.js
|
||||||
|
@ -9,6 +9,7 @@ const spawn = require('child_process').spawn;
|
|||||||
const chokidar = require('chokidar');
|
const chokidar = require('chokidar');
|
||||||
const { bridge } = require('electron').remote.require('./bridge');
|
const { bridge } = require('electron').remote.require('./bridge');
|
||||||
const { time } = require('lib/time-utils.js');
|
const { time } = require('lib/time-utils.js');
|
||||||
|
const { ErrorNotFound } = require('./rest/errors');
|
||||||
|
|
||||||
class ExternalEditWatcher {
|
class ExternalEditWatcher {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -27,16 +28,22 @@ class ExternalEditWatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
externalApi() {
|
externalApi() {
|
||||||
|
const loadNote = async (noteId) => {
|
||||||
|
const note = await Note.load(noteId);
|
||||||
|
if (!note) throw new ErrorNotFound(`No such note: ${noteId}`);
|
||||||
|
return note;
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
openAndWatch: async ({ noteId }) => {
|
openAndWatch: async ({ noteId }) => {
|
||||||
const note = await Note.load(noteId);
|
const note = await loadNote(noteId);
|
||||||
return this.openAndWatch(note);
|
return this.openAndWatch(note);
|
||||||
},
|
},
|
||||||
stopWatching: async ({ noteId }) => {
|
stopWatching: async ({ noteId }) => {
|
||||||
return this.stopWatching(noteId);
|
return this.stopWatching(noteId);
|
||||||
},
|
},
|
||||||
noteIsWatched: async ({ noteId }) => {
|
noteIsWatched: async ({ noteId }) => {
|
||||||
const note = await Note.load(noteId);
|
const note = await loadNote(noteId);
|
||||||
return this.noteIsWatched(note);
|
return this.noteIsWatched(note);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -24,38 +24,7 @@ const { FoldersScreenUtils } = require('lib/folders-screen-utils.js');
|
|||||||
const uri2path = require('file-uri-to-path');
|
const uri2path = require('file-uri-to-path');
|
||||||
const { MarkupToHtml } = require('lib/joplin-renderer');
|
const { MarkupToHtml } = require('lib/joplin-renderer');
|
||||||
const { uuid } = require('lib/uuid');
|
const { uuid } = require('lib/uuid');
|
||||||
|
const { ErrorMethodNotAllowed, ErrorForbidden, ErrorBadRequest, ErrorNotFound } = require('./errors');
|
||||||
class ApiError extends Error {
|
|
||||||
constructor(message, httpCode = 400) {
|
|
||||||
super(message);
|
|
||||||
this.httpCode_ = httpCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
get httpCode() {
|
|
||||||
return this.httpCode_;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ErrorMethodNotAllowed extends ApiError {
|
|
||||||
constructor(message = 'Method Not Allowed') {
|
|
||||||
super(message, 405);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
class ErrorNotFound extends ApiError {
|
|
||||||
constructor(message = 'Not Found') {
|
|
||||||
super(message, 404);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
class ErrorForbidden extends ApiError {
|
|
||||||
constructor(message = 'Forbidden') {
|
|
||||||
super(message, 403);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
class ErrorBadRequest extends ApiError {
|
|
||||||
constructor(message = 'Bad Request') {
|
|
||||||
super(message, 400);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Api {
|
class Api {
|
||||||
constructor(token = null, actionApi = null) {
|
constructor(token = null, actionApi = null) {
|
||||||
|
33
ReactNativeClient/lib/services/rest/errors.ts
Normal file
33
ReactNativeClient/lib/services/rest/errors.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
class ApiError extends Error {
|
||||||
|
private httpCode_:number;
|
||||||
|
|
||||||
|
constructor(message:string, httpCode:number = 400) {
|
||||||
|
super(message);
|
||||||
|
this.httpCode_ = httpCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
get httpCode() {
|
||||||
|
return this.httpCode_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ErrorMethodNotAllowed extends ApiError {
|
||||||
|
constructor(message = 'Method Not Allowed') {
|
||||||
|
super(message, 405);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export class ErrorNotFound extends ApiError {
|
||||||
|
constructor(message = 'Not Found') {
|
||||||
|
super(message, 404);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export class ErrorForbidden extends ApiError {
|
||||||
|
constructor(message = 'Forbidden') {
|
||||||
|
super(message, 403);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export class ErrorBadRequest extends ApiError {
|
||||||
|
constructor(message = 'Bad Request') {
|
||||||
|
super(message, 400);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user