chore(core): integrate errors

This commit is contained in:
Elian Doran 2026-01-06 11:31:13 +02:00
parent 320d8e3b45
commit af8744ef2a
No known key found for this signature in database
13 changed files with 64 additions and 80 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -1,9 +0,0 @@
class OpenIdError {
message: string;
constructor(message: string) {
this.message = message;
}
}
export default OpenIdError;

View File

@ -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;

View File

@ -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) {

View File

@ -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);

View File

@ -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) {

View File

@ -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";

View File

@ -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";

View 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";
}
}

View File

@ -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 }: {

View File

@ -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";