File tree Expand file tree Collapse file tree 6 files changed +24
-15
lines changed
infrastructure/environments
src/app/_components/client-unhandled-error-logger Expand file tree Collapse file tree 6 files changed +24
-15
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ SSM_PREFIX=/local/
33
44# logging
55PINO_LOG_LEVEL = info
6+ NEXT_PUBLIC_SUPRESS_CONSOLE = false
67PROFILE_PERFORMANCE = true
78DEPLOY_ENVIRONMENT = local
89
Original file line number Diff line number Diff line change @@ -25,9 +25,10 @@ locals {
2525 application_environment_variables = {
2626 SSM_PREFIX = " /${ local . prefix } /"
2727
28- PINO_LOG_LEVEL = " info"
29- DEPLOY_ENVIRONMENT = local.environment
30- PROFILE_PERFORMANCE = " true"
28+ PINO_LOG_LEVEL = " info"
29+ NEXT_PUBLIC_SUPRESS_CONSOLE = " false"
30+ DEPLOY_ENVIRONMENT = local.environment
31+ PROFILE_PERFORMANCE = " true"
3132
3233 CONTENT_API_ENDPOINT = " https://int.api.service.nhs.uk/"
3334 CONTENT_CACHE_PATH = " s3://${ local . content_cache_bucket_name } "
Original file line number Diff line number Diff line change @@ -25,9 +25,10 @@ locals {
2525 application_environment_variables = {
2626 SSM_PREFIX = " /${ local . prefix } /"
2727
28- PINO_LOG_LEVEL = " info"
29- DEPLOY_ENVIRONMENT = local.environment
30- PROFILE_PERFORMANCE = " true"
28+ PINO_LOG_LEVEL = " info"
29+ NEXT_PUBLIC_SUPRESS_CONSOLE = " false"
30+ DEPLOY_ENVIRONMENT = local.environment
31+ PROFILE_PERFORMANCE = " true"
3132
3233 CONTENT_API_ENDPOINT = " https://int.api.service.nhs.uk/"
3334 CONTENT_CACHE_PATH = " s3://${ local . content_cache_bucket_name } "
Original file line number Diff line number Diff line change @@ -25,9 +25,10 @@ locals {
2525 application_environment_variables = {
2626 SSM_PREFIX = " /${ local . prefix } /"
2727
28- PINO_LOG_LEVEL = " info"
29- DEPLOY_ENVIRONMENT = local.environment
30- PROFILE_PERFORMANCE = " true"
28+ PINO_LOG_LEVEL = " info"
29+ NEXT_PUBLIC_SUPRESS_CONSOLE = " true"
30+ DEPLOY_ENVIRONMENT = local.environment
31+ PROFILE_PERFORMANCE = " true"
3132
3233 CONTENT_API_ENDPOINT = " https://api.service.nhs.uk/"
3334 CONTENT_CACHE_PATH = " s3://${ local . content_cache_bucket_name } "
Original file line number Diff line number Diff line change @@ -25,9 +25,10 @@ locals {
2525 application_environment_variables = {
2626 SSM_PREFIX = " /${ local . prefix } /"
2727
28- PINO_LOG_LEVEL = " debug"
29- DEPLOY_ENVIRONMENT = local.environment
30- PROFILE_PERFORMANCE = " true"
28+ PINO_LOG_LEVEL = " debug"
29+ NEXT_PUBLIC_SUPRESS_CONSOLE = " true"
30+ DEPLOY_ENVIRONMENT = local.environment
31+ PROFILE_PERFORMANCE = " true"
3132
3233 CONTENT_API_ENDPOINT = " https://int.api.service.nhs.uk/"
3334 CONTENT_CACHE_PATH = " s3://${ local . content_cache_bucket_name } "
Original file line number Diff line number Diff line change @@ -5,18 +5,22 @@ import { ClientSideErrorTypes } from "@src/utils/constants";
55import { useRouter } from "next/navigation" ;
66import { useEffect } from "react" ;
77
8+ const supressConsole = ( process . env . NEXT_PUBLIC_SUPRESS_CONSOLE ?? "true" ) !== "false" ;
89let router ;
910
1011const reportClientSideUnhandledError = ( errorEvent : ErrorEvent ) => {
11- errorEvent . preventDefault ( ) ;
12- logClientSideError ( ClientSideErrorTypes . UNHANDLED_ERROR ) . catch ( ( ) => {
12+ if ( supressConsole ) errorEvent . preventDefault ( ) ;
13+
14+ logClientSideError ( ClientSideErrorTypes . UNHANDLED_ERROR ) . catch ( ( err : Error ) => {
15+ if ( ! supressConsole ) console . error ( err . message ) ;
1316 // do not show anything to the user; catching prevents an infinite loop if the logger itself throws an error which is unhandled
1417 } ) ;
1518 router . push ( "/service-failure" ) ;
1619} ;
1720
1821const reportClientSideUnhandledPromiseRejectionError = ( ) => {
19- logClientSideError ( ClientSideErrorTypes . UNHANDLED_PROMISE_REJECT_ERROR ) . catch ( ( ) => {
22+ logClientSideError ( ClientSideErrorTypes . UNHANDLED_PROMISE_REJECT_ERROR ) . catch ( ( err : Error ) => {
23+ if ( ! supressConsole ) console . error ( err . message ) ;
2024 // do not show anything to the user; catching prevents an infinite loop if the logger itself throws an error which is unhandled
2125 } ) ;
2226 router . push ( "/service-failure" ) ;
You can’t perform that action at this time.
0 commit comments