From 28c639ff9e40999dd0e2d0f6fb5c2bbdfc1921dd Mon Sep 17 00:00:00 2001 From: birkirkristmunds <142495885+birkirkristmunds@users.noreply.github.com> Date: Fri, 13 Dec 2024 17:08:31 +0000 Subject: [PATCH] fix(skilavottord): Fix error message being shown if vehicle is not found for registration (#16852) * TS-933 Fix error msg being shown if vehicle is not found for registration * TS-933 Fixed typo --------- Co-authored-by: veronikasif <54938148+veronikasif@users.noreply.github.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- apps/skilavottord/web/graphql/errorLink.ts | 7 +++++-- .../DeregisterVehicle/Confirm/Confirm.tsx | 3 +++ .../DeregisterVehicle/Overview/Overview.tsx | 20 +++++++++---------- apps/skilavottord/web/utils/roleUtils.ts | 4 +++- .../recyclingRequest.service.ts | 19 +++++++++++++++--- 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/apps/skilavottord/web/graphql/errorLink.ts b/apps/skilavottord/web/graphql/errorLink.ts index 59cdc715ed61..15c86f40a958 100644 --- a/apps/skilavottord/web/graphql/errorLink.ts +++ b/apps/skilavottord/web/graphql/errorLink.ts @@ -1,5 +1,5 @@ import { onError, ErrorResponse } from '@apollo/client/link/error' -import { signIn, signOut } from 'next-auth/client' +import { signIn } from 'next-auth/client' import { toast } from '@island.is/island-ui/core' @@ -22,7 +22,10 @@ export default onError(({ graphQLErrors, networkError }: ErrorResponse) => { }) } return - } else if (errorCodes.includes('FORBIDDEN')) { + } else if ( + errorCodes.includes('FORBIDDEN') || + (graphQLErrors[0]?.extensions as any)?.response?.error === 'NOT_FOUND' + ) { return } diff --git a/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx b/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx index a8b25824b009..c102ea78bf04 100644 --- a/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx +++ b/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx @@ -133,6 +133,9 @@ const Confirm: FC> = () => { SkilavottordVehicleReadyToDeregisteredQuery, { variables: { permno: id }, + onError: (_err) => { + // Do nothing error handled in ErrorLink + }, }, ) diff --git a/apps/skilavottord/web/screens/DeregisterVehicle/Overview/Overview.tsx b/apps/skilavottord/web/screens/DeregisterVehicle/Overview/Overview.tsx index 859ecd9b4dbf..ae383ea2a2f9 100644 --- a/apps/skilavottord/web/screens/DeregisterVehicle/Overview/Overview.tsx +++ b/apps/skilavottord/web/screens/DeregisterVehicle/Overview/Overview.tsx @@ -1,34 +1,32 @@ -import React, { FC, useContext, useEffect, useRef } from 'react' -import Link from 'next/link' -import { useRouter } from 'next/router' import { useQuery } from '@apollo/client' import gql from 'graphql-tag' +import Link from 'next/link' +import { useRouter } from 'next/router' +import React, { FC, useContext, useEffect, useRef } from 'react' import { Box, - Stack, - Text, BreadcrumbsDeprecated as Breadcrumbs, Button, GridColumn, LoadingDots, + Stack, + Text, } from '@island.is/island-ui/core' -import { useI18n } from '@island.is/skilavottord-web/i18n' -import { UserContext } from '@island.is/skilavottord-web/context' import { hasPermission } from '@island.is/skilavottord-web/auth/utils' import { - Sidenav, NotFound, PartnerPageLayout, + Sidenav, } from '@island.is/skilavottord-web/components' +import { UserContext } from '@island.is/skilavottord-web/context' import { - RecyclingPartner, - RecyclingRequest, - Vehicle, Query, Role, + Vehicle, } from '@island.is/skilavottord-web/graphql/schema' +import { useI18n } from '@island.is/skilavottord-web/i18n' import { BASE_PATH } from '@island.is/skilavottord/consts' import { CarsTable } from './components/CarsTable' diff --git a/apps/skilavottord/web/utils/roleUtils.ts b/apps/skilavottord/web/utils/roleUtils.ts index 2cf4bb6cfe9b..793c56126f3f 100644 --- a/apps/skilavottord/web/utils/roleUtils.ts +++ b/apps/skilavottord/web/utils/roleUtils.ts @@ -12,7 +12,9 @@ export const getRoleTranslation = (role: Role, locale: Locale): string => { case 'recyclingFund': return locale === 'is' ? 'Úrvinnslusjóður' : 'Recycling Fund' case 'recyclingCompanyAdmin': - return locale === 'is' ? 'Mótökuaðili umsýsla' : 'Recycling Company Admin' + return locale === 'is' + ? 'Móttökuaðili umsýsla' + : 'Recycling Company Admin' default: return startCase(role) } diff --git a/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.service.ts b/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.service.ts index b84bedcff8ea..afb5ea568a87 100644 --- a/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.service.ts +++ b/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.service.ts @@ -1,4 +1,9 @@ -import { Inject, Injectable, forwardRef } from '@nestjs/common' +import { + Inject, + Injectable, + NotFoundException, + forwardRef, +} from '@nestjs/common' import { HttpService } from '@nestjs/axios' import { InjectModel } from '@nestjs/sequelize' import format from 'date-fns/format' @@ -159,8 +164,12 @@ export class RecyclingRequestService { ) } } else { - throw new Error( - `Could not find any requestType for vehicle's number: ${loggedPermno} in database`, + this.logger.warn( + `car-recycling: Could not find any requestType for vehicle's number: ${loggedPermno} in database from partner ${user.partnerId}`, + ) + throw new NotFoundException( + `Could not find any requestType for vehicle's number: ${loggedPermno} in database from partner ${user.partnerId}`, + 'NOT_FOUND', ) } @@ -173,6 +182,10 @@ export class RecyclingRequestService { } return res } catch (err) { + if (err instanceof NotFoundException) { + throw err + } + throw new Error( `Failed on getVehicleInfoToDeregistered request from partner ${user.partnerId} with error: ${err}`, )