Skip to content

Commit

Permalink
fix(skilavottord): Fix error message being shown if vehicle is not fo…
Browse files Browse the repository at this point in the history
…und 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 <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 13, 2024
1 parent 55aae3d commit 28c639f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 17 deletions.
7 changes: 5 additions & 2 deletions apps/skilavottord/web/graphql/errorLink.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ const Confirm: FC<React.PropsWithChildren<unknown>> = () => {
SkilavottordVehicleReadyToDeregisteredQuery,
{
variables: { permno: id },
onError: (_err) => {
// Do nothing error handled in ErrorLink
},
},
)

Expand Down
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
4 changes: 3 additions & 1 deletion apps/skilavottord/web/utils/roleUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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',
)
}

Expand All @@ -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}`,
)
Expand Down

0 comments on commit 28c639f

Please sign in to comment.