Make the "Please Log In" text link to the login page

This commit is contained in:
rubikscraft
2022-09-01 18:58:47 +02:00
parent 83cc652b52
commit 7962adb5ca
3 changed files with 36 additions and 6 deletions

View File

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

View File

@@ -7,7 +7,7 @@
</ngx-dropzone>
<div class="centered" *ngIf="!canUpload">
<h1>Please Log In</h1>
<h1><a routerLink="/user/login">Please Log In</a></h1>
<p>You do not yet have permission to upload</p>
</div>
</div>

View File

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