diff --git a/lib/routes/test/config-not-found-error.ts b/lib/routes/test/config-not-found-error.ts new file mode 100644 index 000000000..0184edad7 --- /dev/null +++ b/lib/routes/test/config-not-found-error.ts @@ -0,0 +1,22 @@ +import { Route } from '@/types'; +import ConfigNotFoundError from '@/errors/types/config-not-found'; + +export const route: Route = { + path: '/config-not-found-error', + name: 'config-not-found-error', + maintainers: ['DIYgod'], + example: '/config-not-found-error', + handler, +}; + +function handler() { + throw new ConfigNotFoundError('Test config not found error'); + return { + title: 'Title', + items: [ + { + title: 'Title', + }, + ], + }; +} diff --git a/lib/routes/test/error.ts b/lib/routes/test/error.ts new file mode 100644 index 000000000..e07fedf5c --- /dev/null +++ b/lib/routes/test/error.ts @@ -0,0 +1,21 @@ +import { Route } from '@/types'; + +export const route: Route = { + path: '/error', + name: 'error', + maintainers: ['DIYgod'], + example: '/error', + handler, +}; + +function handler() { + throw new Error('Error test'); + return { + title: 'Title', + items: [ + { + title: 'Title', + }, + ], + }; +} diff --git a/lib/routes/test/httperror.ts b/lib/routes/test/httperror.ts new file mode 100644 index 000000000..3584be7cf --- /dev/null +++ b/lib/routes/test/httperror.ts @@ -0,0 +1,25 @@ +import { Route } from '@/types'; +import got from '@/utils/got'; + +export const route: Route = { + path: '/httperror', + name: 'httperror', + maintainers: ['DIYgod'], + example: '/httperror', + handler, +}; + +async function handler() { + await got({ + method: 'get', + url: 'https://httpbingo.org/status/404', + }); + return { + title: 'Title', + items: [ + { + title: 'Title', + }, + ], + }; +} diff --git a/lib/routes/test/index.ts b/lib/routes/test/index.ts index 2990917bd..78c4f64cf 100644 --- a/lib/routes/test/index.ts +++ b/lib/routes/test/index.ts @@ -1,37 +1,20 @@ import { Route, DataItem } from '@/types'; import { config } from '@/config'; -import got from '@/utils/got'; import wait from '@/utils/wait'; import cache from '@/utils/cache'; import { fetchArticle } from '@/utils/wechat-mp'; -import ConfigNotFoundError from '@/errors/types/config-not-found'; import InvalidParameterError from '@/errors/types/invalid-parameter'; let cacheIndex = 0; export const route: Route = { path: '/:id/:params?', - name: 'Unknown', + name: 'Test', maintainers: ['DIYgod', 'NeverBehave'], handler, }; async function handler(ctx) { - if (ctx.req.param('id') === 'error') { - throw new Error('Error test'); - } - if (ctx.req.param('id') === 'httperror') { - await got({ - method: 'get', - url: 'https://httpbingo.org/status/404', - }); - } - if (ctx.req.param('id') === 'config-not-found-error') { - throw new ConfigNotFoundError('Test config not found error'); - } - if (ctx.req.param('id') === 'invalid-parameter-error') { - throw new InvalidParameterError('Test invalid parameter error'); - } let item: DataItem[] = []; switch (ctx.req.param('id')) { case 'filter': diff --git a/lib/routes/test/invalid-parameter-error.ts b/lib/routes/test/invalid-parameter-error.ts new file mode 100644 index 000000000..9512f47d8 --- /dev/null +++ b/lib/routes/test/invalid-parameter-error.ts @@ -0,0 +1,22 @@ +import { Route } from '@/types'; +import InvalidParameterError from '@/errors/types/invalid-parameter'; + +export const route: Route = { + path: '/invalid-parameter-error', + name: 'invalid-parameter-error', + maintainers: ['DIYgod'], + example: '/invalid-parameter-error', + handler, +}; + +function handler() { + throw new InvalidParameterError('Test invalid parameter error'); + return { + title: 'Title', + items: [ + { + title: 'Title', + }, + ], + }; +} diff --git a/lib/routes/test/namespace.ts b/lib/routes/test/namespace.ts index f236265dc..27224d001 100644 --- a/lib/routes/test/namespace.ts +++ b/lib/routes/test/namespace.ts @@ -1,5 +1,5 @@ import type { Namespace } from '@/types'; export const namespace: Namespace = { - name: 'Unknown', + name: 'RSSHub Test', };