From 7962adb5ca78df7c8612294c9cfe3ddd2f70f092 Mon Sep 17 00:00:00 2001 From: rubikscraft Date: Thu, 1 Sep 2022 18:58:47 +0200 Subject: [PATCH] Make the "Please Log In" text link to the login page --- .../src/layers/exception/exception.filter.ts | 23 +++++++++++++++---- .../app/routes/upload/upload.component.html | 2 +- .../app/routes/upload/upload.component.scss | 17 ++++++++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/backend/src/layers/exception/exception.filter.ts b/backend/src/layers/exception/exception.filter.ts index 1691eb1..d1542f5 100644 --- a/backend/src/layers/exception/exception.filter.ts +++ b/backend/src/layers/exception/exception.filter.ts @@ -1,4 +1,4 @@ -import { ArgumentsHost, Catch, ExceptionFilter, Logger } from '@nestjs/common'; +import { ArgumentsHost, Catch, ExceptionFilter, ForbiddenException, Logger, MethodNotAllowedException, NotFoundException, UnauthorizedException } from '@nestjs/common'; import { FastifyReply, FastifyRequest } from 'fastify'; import { ApiErrorResponse } from 'picsur-shared/dist/dto/api/api.dto'; import { @@ -24,10 +24,7 @@ export class MainExceptionFilter implements ExceptionFilter { const traceString = `(${request.ip} -> ${request.method} ${request.url})`; if (!IsFailure(exception)) { - MainExceptionFilter.logger.error( - traceString + ' Unkown exception: ' + exception, - ); - exception = Fail(FT.Internal, 'Unknown exception', exception); + exception = this.transformKnownExceptions(exception); } const status = exception.getCode(); @@ -65,4 +62,20 @@ export class MainExceptionFilter implements ExceptionFilter { response.status(status).send(toSend); } + + private transformKnownExceptions(exception: any): Failure { + if (exception instanceof UnauthorizedException) { + return Fail(FT.Permission, exception); + } else if (exception instanceof ForbiddenException) { + return Fail(FT.Permission, exception); + } else if (exception instanceof NotFoundException) { + return Fail(FT.NotFound, exception); + } else if (exception instanceof MethodNotAllowedException) { + return Fail(FT.NotFound, exception); + } else if (exception instanceof Error) { + return Fail(FT.Internal, exception); + } else { + return Fail(FT.Unknown, exception); + } + } } diff --git a/frontend/src/app/routes/upload/upload.component.html b/frontend/src/app/routes/upload/upload.component.html index 21be3fb..f0f14bf 100644 --- a/frontend/src/app/routes/upload/upload.component.html +++ b/frontend/src/app/routes/upload/upload.component.html @@ -7,7 +7,7 @@
-

Please Log In

+

Please Log In

You do not yet have permission to upload

diff --git a/frontend/src/app/routes/upload/upload.component.scss b/frontend/src/app/routes/upload/upload.component.scss index ebe5893..462c15d 100644 --- a/frontend/src/app/routes/upload/upload.component.scss +++ b/frontend/src/app/routes/upload/upload.component.scss @@ -20,3 +20,20 @@ ngx-dropzone { .centered { padding-inline: 1rem; } + +// unstyle a href +a { + color: inherit; + text-decoration: inherit; + + &:hover { + color: inherit; + text-decoration: underline; + } + + &:active { + color: inherit; + text-decoration: underline; + } +} +