Skip to content

Commit

Permalink
Merge pull request #646 from energywebfoundation/task/SWTCH-2403_text…
Browse files Browse the repository at this point in the history
…_based_content_injection

SWTCH-2403 Text based content injection
  • Loading branch information
JGiter authored May 31, 2023
2 parents 56852b9 + a8bd59a commit 844b005
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Class: NotFoundExceptionFilter

[common/not-found-exception-filter](../modules/common_not_found_exception_filter.md).NotFoundExceptionFilter

## Implements

- `ExceptionFilter`

## Table of contents

### Constructors

- [constructor](common_not_found_exception_filter.NotFoundExceptionFilter.md#constructor)

### Methods

- [catch](common_not_found_exception_filter.NotFoundExceptionFilter.md#catch)

## Constructors

### constructor

**new NotFoundExceptionFilter**()

## Methods

### catch

**catch**(`exception`, `host`): `void`

#### Parameters

| Name | Type |
| :------ | :------ |
| `exception` | `any` |
| `host` | `ArgumentsHost` |

#### Returns

`void`

#### Implementation of

ExceptionFilter.catch
1 change: 1 addition & 0 deletions docs/api/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- [common/constants](modules/common_constants.md)
- [common/cors.config](modules/common_cors_config.md)
- [common/json.scalar](modules/common_json_scalar.md)
- [common/not-found-exception-filter](modules/common_not_found_exception_filter.md)
- [common/provider](modules/common_provider.md)
- [common/test.utils](modules/common_test_utils.md)
- [common/url-decode.decorator](modules/common_url_decode_decorator.md)
Expand Down
7 changes: 7 additions & 0 deletions docs/api/modules/common_not_found_exception_filter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Module: common/not-found-exception-filter

## Table of contents

### Classes

- [NotFoundExceptionFilter](../classes/common_not_found_exception_filter.NotFoundExceptionFilter.md)
18 changes: 18 additions & 0 deletions src/common/not-found-exception-filter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {
ArgumentsHost,
Catch,
ExceptionFilter,
NotFoundException,
} from '@nestjs/common';
import { Response } from 'express';

@Catch(NotFoundException)
export class NotFoundExceptionFilter implements ExceptionFilter {
catch(exception: any, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const response = ctx.getResponse<Response>();
const status = exception.getStatus();

response.status(status).send('<html>Page not found</html>');
}
}
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SentryService } from './modules/sentry/sentry.service';
import * as SentryNode from '@sentry/node';
import { corsConfig } from './common/cors.config';
import { setupSwagger } from './setup-swagger.function';
import { NotFoundExceptionFilter } from './common/not-found-exception-filter';

// This allows TypeScript to detect our global value and properly assign maps for sentry
// See more here: https://docs.sentry.io/platforms/node/typescript/
Expand Down Expand Up @@ -42,6 +43,7 @@ async function bootstrap() {
type: VersioningType.URI,
});
app.useGlobalPipes(new ValidationPipe());
app.useGlobalFilters(new NotFoundExceptionFilter());

// add security middleware
app.use(
Expand Down

0 comments on commit 844b005

Please sign in to comment.