From e030bfb59dd5ee65f20a64686ec9b22ca39f70ae Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 2 Jun 2021 18:15:41 +0200 Subject: Refactor server errors handler --- shared/models/server/index.ts | 1 + .../server/peertube-problem-document.model.ts | 32 ++++++++++++++++++++++ shared/models/server/server-error-code.enum.ts | 10 ++++++- 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 shared/models/server/peertube-problem-document.model.ts (limited to 'shared/models') diff --git a/shared/models/server/index.ts b/shared/models/server/index.ts index b5163954a..06bf5c599 100644 --- a/shared/models/server/index.ts +++ b/shared/models/server/index.ts @@ -6,6 +6,7 @@ export * from './debug.model' export * from './emailer.model' export * from './job.model' export * from './log-level.type' +export * from './peertube-problem-document.model' export * from './server-config.model' export * from './server-debug.model' export * from './server-error-code.enum' diff --git a/shared/models/server/peertube-problem-document.model.ts b/shared/models/server/peertube-problem-document.model.ts new file mode 100644 index 000000000..5e1c320f3 --- /dev/null +++ b/shared/models/server/peertube-problem-document.model.ts @@ -0,0 +1,32 @@ +import { HttpStatusCode } from '@shared/core-utils' +import { OAuth2ErrorCode, ServerErrorCode } from './server-error-code.enum' + +export interface PeerTubeProblemDocumentData { + 'invalid-params'?: Record + + originUrl?: string + + keyId?: string + + targetUrl?: string + + actorUrl?: string + + // Feeds + format?: string + url?: string +} + +export interface PeerTubeProblemDocument extends PeerTubeProblemDocumentData { + type: string + title: string + + detail: string + // Compat PeerTube <= 3.2 + error: string + + status: HttpStatusCode + + docs?: string + code?: ServerErrorCode | OAuth2ErrorCode +} diff --git a/shared/models/server/server-error-code.enum.ts b/shared/models/server/server-error-code.enum.ts index 93b9ce20d..43996e7aa 100644 --- a/shared/models/server/server-error-code.enum.ts +++ b/shared/models/server/server-error-code.enum.ts @@ -48,5 +48,13 @@ export const enum OAuth2ErrorCode { * * @see https://github.com/oauthjs/node-oauth2-server/blob/master/lib/errors/invalid-client-error.js */ - INVALID_CLIENT = 'invalid_client' + INVALID_CLIENT = 'invalid_client', + + + /** + * The access token provided is expired, revoked, malformed, or invalid for other reasons + * + * @see https://github.com/oauthjs/node-oauth2-server/blob/master/lib/errors/invalid-token-error.js + */ + INVALID_TOKEN = 'invalid_token', } -- cgit v1.2.3