11import { Config } from "../config" ;
2- import axios from "axios" ;
2+ import axios , { AxiosError } from "axios" ;
33import axiosRetry from "axios-retry" ;
44import { Log , LoggerToUse } from "../logging" ;
55import { redisClient } from "../app" ;
@@ -11,12 +11,13 @@ export interface Entry {
1111}
1212
1313export type SearchAllFailed = {
14- Succeeded : false
14+ Succeeded : false ,
15+ Reason : "unknown" | "team_not_found"
1516}
1617
1718export type SearchAllSucceeded = {
1819 Succeeded : true ,
19- entries : Entry [ ]
20+ entries : Entry [ ]
2021}
2122
2223export type SearchAllResponse = Promise < SearchAllFailed | SearchAllSucceeded >
@@ -77,16 +78,17 @@ async function ForwardSearch(groupName: string): SearchAllResponse {
7778 Log ( `Retrieving group (${ groupName } ) information from '${ requestUrl } '` ) ;
7879 try {
7980 const httpResponse = await httpClient . get ( requestUrl ) ;
80- Log ( `Results for ${ groupName } : ${ JSON . stringify ( httpResponse . data ) } ` ) ;
81+ Log ( `Results for ${ groupName } : ${ JSON . stringify ( httpResponse . data ) } ` ) ;
8182
82- if ( httpResponse . status < 200 || httpResponse . status > 299 ) {
83+ if ( httpResponse . status < 200 || httpResponse . status > 299 ) {
8384 return {
84- Succeeded : false
85+ Succeeded : false ,
86+ Reason : "unknown"
8587 }
86- }
88+ }
8789
8890 const response = httpResponse . data as SuccessResponse ;
89-
91+
9092 return {
9193 Succeeded : true ,
9294 entries : response . users . map ( u => {
@@ -99,10 +101,21 @@ async function ForwardSearch(groupName: string): SearchAllResponse {
99101 }
100102 catch ( e ) {
101103 Log ( `Error when retrieving results for ${ groupName } : ${ e } ` ) ;
104+
105+ if ( e instanceof ( AxiosError ) ) {
106+ const axiosError = e as AxiosError ;
107+ if ( axiosError . response ?. status == 404 ) {
108+ return {
109+ Succeeded : false ,
110+ Reason : "team_not_found"
111+ }
112+ }
113+ }
102114 }
103115
104116 return {
105- Succeeded : false
117+ Succeeded : false ,
118+ Reason : "unknown"
106119 }
107120}
108121
@@ -111,12 +124,12 @@ export interface User {
111124 email : string
112125}
113126
114- export interface SuccessResponse {
115- users : User [ ]
127+ export interface SuccessResponse {
128+ users : User [ ]
116129}
117130
118- export interface FailedResponse {
131+ export interface FailedResponse {
119132 Message : string
120133}
121134
122- export type SearchResponse = SuccessResponse | FailedResponse
135+ export type SearchResponse = SuccessResponse | FailedResponse ;
0 commit comments