Skip to content

Commit 61cf4e3

Browse files
committed
fix(project): Show backend conflict message with modified date when creating duplicate project
Signed-off-by: suhas-SHS <[email protected]>
1 parent 51491b2 commit 61cf4e3

File tree

2 files changed

+47
-13
lines changed

2 files changed

+47
-13
lines changed

src/app/[locale]/projects/add/page.tsx

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function AddProjects(): JSX.Element {
103103
])
104104

105105
useEffect(() => {
106-
;(async () => {
106+
; (async () => {
107107
try {
108108
const session = await getSession()
109109
if (CommonUtils.isNullOrUndefined(session)) {
@@ -152,21 +152,37 @@ function AddProjects(): JSX.Element {
152152
}
153153

154154
const createProject = async () => {
155+
const session = await getSession()
156+
if (CommonUtils.isNullOrUndefined(session)) return signOut()
157+
const createUrl = isDependencyNetworkFeatureEnabled === true ? `projects/network` : 'projects'
155158
try {
156-
const session = await getSession()
157-
if (CommonUtils.isNullOrUndefined(session)) return signOut()
158-
const createUrl = isDependencyNetworkFeatureEnabled === true ? `projects/network` : 'projects'
159159
const response = await ApiUtils.POST(createUrl, projectPayload, session.user.access_token)
160160

161161
if (response.status == StatusCodes.CREATED) {
162162
const data = (await response.json()) as Project
163163
MessageService.success(t('Your project is created'))
164164
router.push(`/projects/detail/${data._links.self.href.split('/').at(-1)}`)
165+
}
166+
else if (response.status === StatusCodes.CONFLICT) {
167+
const body = await response.json().catch(() => ({}))
168+
const msg = body?.message ?? t('SW360 project already exists')
169+
MessageService.error(`${msg}`)
165170
} else {
166171
MessageService.error(t('There are some errors while creating project'))
167172
}
168-
} catch (e) {
169-
console.error(e)
173+
} catch (err: unknown) {
174+
const res = (err as Response) ?? {}
175+
if ('status' in res && res.status === StatusCodes.CONFLICT) {
176+
let msg = t('SW360 project already exists')
177+
try {
178+
const body = await res.json()
179+
msg = body?.message ?? msg
180+
} catch { }
181+
MessageService.error(`${msg}`)
182+
return
183+
}
184+
185+
MessageService.error(t('There are some errors while creating project'))
170186
}
171187
}
172188

src/app/[locale]/projects/duplicate/[id]/components/DuplicateProject.tsx

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -379,13 +379,31 @@ function DuplicateProject({ projectId, isDependencyNetworkFeatureEnabled }: Prop
379379
isDependencyNetworkFeatureEnabled === true
380380
? `projects/network/duplicate/${projectId}`
381381
: `projects/duplicate/${projectId}`
382-
const response = await ApiUtils.POST(createProjectUrl, projectPayload, session.user.access_token)
383-
384-
if (response.status == StatusCodes.CREATED) {
385-
const data = (await response.json()) as Project
386-
MessageService.success(t('Your project is created'))
387-
router.push(`/projects/detail/${data._links.self.href.split('/').at(-1)}`)
388-
} else {
382+
try {
383+
const response = await ApiUtils.POST(createProjectUrl, projectPayload, session.user.access_token)
384+
385+
if (response.status == StatusCodes.CREATED) {
386+
const data = (await response.json()) as Project
387+
MessageService.success(t('Your project is created'))
388+
router.push(`/projects/detail/${data._links.self.href.split('/').at(-1)}`)
389+
} else if (response.status === StatusCodes.CONFLICT) {
390+
const body = await response.json().catch(() => ({}))
391+
const msg = body?.message ?? t('SW360 project already exists')
392+
MessageService.error(`${msg}`)
393+
} else {
394+
MessageService.error(t('There are some errors while creating project'))
395+
}
396+
} catch (err: unknown) {
397+
const res = (err as Response) ?? {}
398+
if ('status' in res && res.status === StatusCodes.CONFLICT) {
399+
let msg = t('SW360 project already exists')
400+
try {
401+
const body = await res.json()
402+
msg = body?.message ?? msg
403+
} catch { }
404+
MessageService.error(`${msg}`)
405+
return
406+
}
389407
MessageService.error(t('There are some errors while creating project'))
390408
}
391409
}

0 commit comments

Comments
 (0)