@@ -2,7 +2,8 @@ import type { HttpErrorResponse } from '@angular/common/http'
2
2
import { HttpClient } from '@angular/common/http'
3
3
import { inject , Injectable } from '@angular/core'
4
4
import type { Observable } from 'rxjs'
5
- import { catchError , map , of , ReplaySubject , Subject , takeUntil , tap , throwError } from 'rxjs'
5
+ import { catchError , map , of , ReplaySubject , Subject , takeUntil , tap } from 'rxjs'
6
+ import { ErrorService } from '@seed/services/error/error.service'
6
7
import { SnackbarService } from 'app/core/snackbar/snackbar.service'
7
8
import { naturalSort } from '../../utils'
8
9
import { UserService } from '../user'
@@ -29,6 +30,7 @@ export class OrganizationService {
29
30
private _organizationUsers = new ReplaySubject < OrganizationUser [ ] > ( 1 )
30
31
private _accessLevelTree = new ReplaySubject < AccessLevelTree > ( 1 )
31
32
private _accessLevelInstancesByDepth : AccessLevelsByDepth = { }
33
+ private _errorService = inject ( ErrorService )
32
34
private readonly _unsubscribeAll$ = new Subject < void > ( )
33
35
private _snackBar = inject ( SnackbarService )
34
36
@@ -65,8 +67,7 @@ export class OrganizationService {
65
67
} ) ,
66
68
catchError ( ( error : HttpErrorResponse ) => {
67
69
// TODO need to figure out error handling
68
- console . error ( 'Error occurred fetching organization: ' , error . error )
69
- return of ( { } as Organization )
70
+ return this . _errorService . handleError ( error , 'Error fetching organization' )
70
71
} ) ,
71
72
)
72
73
}
@@ -78,8 +79,7 @@ export class OrganizationService {
78
79
map ( ( response ) => response . users . sort ( ( a , b ) => naturalSort ( a . last_name , b . last_name ) ) ) ,
79
80
tap ( ( users ) => { this . _organizationUsers . next ( users ) } ) ,
80
81
catchError ( ( error : HttpErrorResponse ) => {
81
- console . error ( 'Error fetching organization users:' , error )
82
- return of ( [ ] )
82
+ return this . _errorService . handleError ( error , 'Error fetching organization users' )
83
83
} ) ,
84
84
) . subscribe ( )
85
85
}
@@ -100,8 +100,7 @@ export class OrganizationService {
100
100
this . _accessLevelTree . next ( accessLevelTree )
101
101
} ) ,
102
102
catchError ( ( error : HttpErrorResponse ) => {
103
- console . error ( 'Error fetching organization access level tree:' , error )
104
- return of ( { } )
103
+ return this . _errorService . handleError ( error , 'Error fetching organization access level tree' )
105
104
} ) ,
106
105
)
107
106
. subscribe ( )
@@ -114,8 +113,7 @@ export class OrganizationService {
114
113
this . _snackBar . success ( 'Member removed from organization' , 'OK' , true , 3000 )
115
114
} ) ,
116
115
catchError ( ( error : HttpErrorResponse ) => {
117
- console . error ( 'Error deleting organization user:' , error )
118
- return throwError ( ( ) => new Error ( error ?. message || 'Error deleting organization user' ) )
116
+ return this . _errorService . handleError ( error , 'Error removing member from organization' )
119
117
} ) ,
120
118
)
121
119
}
@@ -141,9 +139,7 @@ export class OrganizationService {
141
139
} )
142
140
} ) ,
143
141
catchError ( ( error : HttpErrorResponse ) => {
144
- console . error ( 'Error occurred fetching organization: ' , error . error )
145
- this . _snackBar . alert ( `An error occurred updating the organization: ${ error . error } ` )
146
- return of ( null )
142
+ return this . _errorService . handleError ( error , 'Error updating organization settings' )
147
143
} ) ,
148
144
)
149
145
}
0 commit comments