mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-15 15:44:45 -04:00
enhancement(auth): better error message handling
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
parent
8e57188ab5
commit
ca9836d691
37 changed files with 199 additions and 207 deletions
|
@ -3,14 +3,10 @@
|
|||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import {
|
||||
BadRequestException,
|
||||
CanActivate,
|
||||
Inject,
|
||||
Injectable,
|
||||
} from '@nestjs/common';
|
||||
import { CanActivate, Inject, Injectable } from '@nestjs/common';
|
||||
|
||||
import authConfiguration, { AuthConfig } from '../../config/auth.config';
|
||||
import { FeatureDisabledError } from '../../errors/errors';
|
||||
import { ConsoleLoggerService } from '../../logger/console-logger.service';
|
||||
|
||||
@Injectable()
|
||||
|
@ -26,7 +22,7 @@ export class LoginEnabledGuard implements CanActivate {
|
|||
canActivate(): boolean {
|
||||
if (!this.authConfig.local.enableLogin) {
|
||||
this.logger.debug('Local auth is disabled.', 'canActivate');
|
||||
throw new BadRequestException('Local auth is disabled.');
|
||||
throw new FeatureDisabledError('Local auth is disabled.');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
import { CanActivate, Inject, Injectable } from '@nestjs/common';
|
||||
|
||||
import authConfiguration, { AuthConfig } from '../../config/auth.config';
|
||||
import { RegistrationDisabledError } from '../../errors/errors';
|
||||
import { FeatureDisabledError } from '../../errors/errors';
|
||||
import { ConsoleLoggerService } from '../../logger/console-logger.service';
|
||||
|
||||
@Injectable()
|
||||
|
@ -22,7 +22,7 @@ export class RegistrationEnabledGuard implements CanActivate {
|
|||
canActivate(): boolean {
|
||||
if (!this.authConfig.local.enableRegister) {
|
||||
this.logger.debug('User registration is disabled.', 'canActivate');
|
||||
throw new RegistrationDisabledError();
|
||||
throw new FeatureDisabledError('User registration is disabled');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ const mapOfHedgeDocErrorsToHttpErrors: Map<string, HttpExceptionConstructor> =
|
|||
(object): HttpException => new PayloadTooLargeException(object),
|
||||
],
|
||||
[
|
||||
'RegistrationDisabledError',
|
||||
'FeatureDisabledError',
|
||||
(object): HttpException => new ForbiddenException(object),
|
||||
],
|
||||
]);
|
||||
|
|
|
@ -60,6 +60,6 @@ export class MaximumDocumentLengthExceededError extends Error {
|
|||
name = 'MaximumDocumentLengthExceededError';
|
||||
}
|
||||
|
||||
export class RegistrationDisabledError extends Error {
|
||||
name = 'RegistrationDisabledError';
|
||||
export class FeatureDisabledError extends Error {
|
||||
name = 'FeatureDisabledError';
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue