mirror of
https://github.com/zadam/trilium.git
synced 2026-01-16 19:44:24 +01:00
chore(core): integrate errors
This commit is contained in:
parent
320d8e3b45
commit
af8744ef2a
@ -1,12 +0,0 @@
|
||||
import HttpError from "./http_error.js";
|
||||
|
||||
class ForbiddenError extends HttpError {
|
||||
|
||||
constructor(message: string) {
|
||||
super(message, 403);
|
||||
this.name = "ForbiddenError";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default ForbiddenError;
|
||||
@ -1,13 +0,0 @@
|
||||
class HttpError extends Error {
|
||||
|
||||
statusCode: number;
|
||||
|
||||
constructor(message: string, statusCode: number) {
|
||||
super(message);
|
||||
this.name = "HttpError";
|
||||
this.statusCode = statusCode;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default HttpError;
|
||||
@ -1,12 +0,0 @@
|
||||
import HttpError from "./http_error.js";
|
||||
|
||||
class NotFoundError extends HttpError {
|
||||
|
||||
constructor(message: string) {
|
||||
super(message, 404);
|
||||
this.name = "NotFoundError";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default NotFoundError;
|
||||
@ -1,9 +0,0 @@
|
||||
class OpenIdError {
|
||||
message: string;
|
||||
|
||||
constructor(message: string) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
||||
export default OpenIdError;
|
||||
@ -1,12 +0,0 @@
|
||||
import HttpError from "./http_error.js";
|
||||
|
||||
class ValidationError extends HttpError {
|
||||
|
||||
constructor(message: string) {
|
||||
super(message, 400)
|
||||
this.name = "ValidationError";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default ValidationError;
|
||||
@ -1,14 +1,12 @@
|
||||
"use strict";
|
||||
|
||||
import zipExportService from "../../services/export/zip.js";
|
||||
import singleExportService from "../../services/export/single.js";
|
||||
import opmlExportService from "../../services/export/opml.js";
|
||||
import becca from "../../becca/becca.js";
|
||||
import TaskContext from "../../services/task_context.js";
|
||||
import log from "../../services/log.js";
|
||||
import NotFoundError from "../../errors/not_found_error.js";
|
||||
import { NotFoundError, ValidationError } from "@triliumnext/core";
|
||||
import type { Request, Response } from "express";
|
||||
import ValidationError from "../../errors/validation_error.js";
|
||||
|
||||
import becca from "../../becca/becca.js";
|
||||
import opmlExportService from "../../services/export/opml.js";
|
||||
import singleExportService from "../../services/export/single.js";
|
||||
import zipExportService from "../../services/export/zip.js";
|
||||
import log from "../../services/log.js";
|
||||
import TaskContext from "../../services/task_context.js";
|
||||
import { safeExtractMessageAndStackFromError } from "../../services/utils.js";
|
||||
|
||||
function exportBranch(req: Request, res: Response) {
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
"use strict";
|
||||
import type { AttributeRow, BranchRow, NoteRow } from "@triliumnext/commons";
|
||||
import { NotFoundError } from "@triliumnext/core";
|
||||
import type { Request } from "express";
|
||||
|
||||
import becca from "../../becca/becca.js";
|
||||
import log from "../../services/log.js";
|
||||
import NotFoundError from "../../errors/not_found_error.js";
|
||||
import type { Request } from "express";
|
||||
import type BNote from "../../becca/entities/bnote.js";
|
||||
import type { AttributeRow, BranchRow, NoteRow } from "@triliumnext/commons";
|
||||
import log from "../../services/log.js";
|
||||
|
||||
function getNotesAndBranchesAndAttributes(_noteIds: string[] | Set<string>) {
|
||||
const noteIds = new Set(_noteIds);
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
import { ForbiddenError, HttpError, NotFoundError } from "@triliumnext/core";
|
||||
import type { Application, NextFunction, Request, Response } from "express";
|
||||
|
||||
import log from "../services/log.js";
|
||||
import NotFoundError from "../errors/not_found_error.js";
|
||||
import ForbiddenError from "../errors/forbidden_error.js";
|
||||
import HttpError from "../errors/http_error.js";
|
||||
|
||||
function register(app: Application) {
|
||||
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
import { NotFoundError, ValidationError } from "@triliumnext/core";
|
||||
import express, { type RequestHandler } from "express";
|
||||
import multer from "multer";
|
||||
|
||||
import AbstractBeccaEntity from "../becca/entities/abstract_becca_entity.js";
|
||||
import { namespace } from "../cls_provider.js";
|
||||
import NotFoundError from "../errors/not_found_error.js";
|
||||
import ValidationError from "../errors/validation_error.js";
|
||||
import auth from "../services/auth.js";
|
||||
import cls from "../services/cls.js";
|
||||
import entityChangesService from "../services/entity_changes.js";
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import NoteSet from "../services/search/note_set.js";
|
||||
import NotFoundError from "../errors/not_found_error.js";
|
||||
import { NotFoundError } from "../errors.js";
|
||||
import type BOption from "./entities/boption.js";
|
||||
import type BNote from "./entities/bnote.js";
|
||||
import type BEtapiToken from "./entities/betapi_token.js";
|
||||
|
||||
46
packages/trilium-core/src/errors.ts
Normal file
46
packages/trilium-core/src/errors.ts
Normal file
@ -0,0 +1,46 @@
|
||||
export class HttpError extends Error {
|
||||
|
||||
statusCode: number;
|
||||
|
||||
constructor(message: string, statusCode: number) {
|
||||
super(message);
|
||||
this.name = "HttpError";
|
||||
this.statusCode = statusCode;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class NotFoundError extends HttpError {
|
||||
|
||||
constructor(message: string) {
|
||||
super(message, 404);
|
||||
this.name = "NotFoundError";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class ForbiddenError extends HttpError {
|
||||
|
||||
constructor(message: string) {
|
||||
super(message, 403);
|
||||
this.name = "ForbiddenError";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class OpenIdError {
|
||||
message: string;
|
||||
|
||||
constructor(message: string) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
||||
export class ValidationError extends HttpError {
|
||||
|
||||
constructor(message: string) {
|
||||
super(message, 400)
|
||||
this.name = "ValidationError";
|
||||
}
|
||||
|
||||
}
|
||||
@ -12,6 +12,7 @@ export * as binary_utils from "./services/utils/binary";
|
||||
export { default as date_utils } from "./services/utils/date";
|
||||
export { default as events } from "./services/events";
|
||||
export { getContext, type ExecutionContext } from "./services/context";
|
||||
export * from "./errors";
|
||||
export type { CryptoProvider } from "./services/encryption/crypto";
|
||||
|
||||
export function initializeCore({ dbConfig, executionContext, crypto }: {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { binary_utils } from "@triliumnext/core";
|
||||
|
||||
import becca from "../becca/becca.js";
|
||||
import NotFoundError from "../errors/not_found_error.js";
|
||||
import { NotFoundError } from "../errors";
|
||||
import type { Blob } from "./blob-interface.js";
|
||||
import protectedSessionService from "./protected_session.js";
|
||||
import { hash } from "./utils.js";
|
||||
Loading…
x
Reference in New Issue
Block a user