@@ -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
0 commit comments