@@ -120,7 +120,11 @@ public class DataverseRepository(ID365AppUserService appUserService, ID365WebApi
120
120
public async Task < OFMApplication > GetFundingApplicationAsync ( Guid applicationId )
121
121
{
122
122
var response = await d365WebApiService . SendRetrieveRequestAsync ( appUserService . AZSystemAppUser , $ "{ string . Format ( DataverseQueries . FundingApplicationQuery , applicationId ) } ", formatted : true , pageSize : 5000 ) ;
123
- response . EnsureSuccessStatusCode ( ) ;
123
+ if ( ! response . IsSuccessStatusCode )
124
+ {
125
+ var responseBody = await response . Content . ReadAsStringAsync ( ) ;
126
+ throw new Exception ( $ "GetFundingApplicationAsync({ applicationId } ): HTTP Failure: { responseBody } ") ;
127
+ }
124
128
var json = await response . Content . ReadFromJsonAsync < JsonObject > ( ) ;
125
129
return new OFMApplication ( json ) ;
126
130
}
@@ -129,7 +133,11 @@ public async Task<IEnumerable<OFMApplication>> GetUnprocessedApplicationsAsync(D
129
133
{
130
134
var formattedTime = lastTime . ToString ( "yyyy-MM-ddTHH:mm:ssZ" ) ;
131
135
var response = await d365WebApiService . SendRetrieveRequestAsync ( appUserService . AZSystemAppUser , $ "{ string . Format ( DataverseQueries . UnprocessedApplicationsQuery , formattedTime ) } ", formatted : true , pageSize : 5000 ) ;
132
- response . EnsureSuccessStatusCode ( ) ;
136
+ if ( ! response . IsSuccessStatusCode )
137
+ {
138
+ var responseBody = await response . Content . ReadAsStringAsync ( ) ;
139
+ throw new Exception ( $ "GetUnprocessedApplicationsAsync({ lastTime } ): HTTP Failure: { responseBody } ") ;
140
+ }
133
141
var json = await response . Content . ReadFromJsonAsync < JsonObject > ( ) ;
134
142
var values = json [ "value" ] ? . AsArray ( ) ?? new JsonArray ( ) ;
135
143
return values . Select ( v => new OFMApplication ( v . AsObject ( ) ) ) ;
@@ -139,7 +147,11 @@ public async Task<IEnumerable<OFMApplication>> GetModifiedApplicationsAsync(Date
139
147
{
140
148
var formattedTime = lastProcessedTime . ToString ( "yyyy-MM-ddTHH:mm:ssZ" ) ;
141
149
var response = await d365WebApiService . SendRetrieveRequestAsync ( appUserService . AZSystemAppUser , $ "{ string . Format ( DataverseQueries . ModifiedApplicationsQuery , formattedTime ) } ", formatted : true , pageSize : 5000 ) ;
142
- response . EnsureSuccessStatusCode ( ) ;
150
+ if ( ! response . IsSuccessStatusCode )
151
+ {
152
+ var responseBody = await response . Content . ReadAsStringAsync ( ) ;
153
+ throw new Exception ( $ "GetModifiedApplicationsAsync({ lastProcessedTime } ):HTTP Failure: { responseBody } ") ;
154
+ }
143
155
var json = await response . Content . ReadFromJsonAsync < JsonObject > ( ) ;
144
156
var values = json [ "value" ] ? . AsArray ( ) ?? new JsonArray ( ) ;
145
157
return values . Select ( v => new OFMApplication ( v . AsObject ( ) ) ) ;
@@ -148,7 +160,11 @@ public async Task<IEnumerable<OFMApplication>> GetModifiedApplicationsAsync(Date
148
160
public async Task < IEnumerable < ScoreParameter > > GetScoreParametersAsync ( Guid calculatorId )
149
161
{
150
162
var response = await d365WebApiService . SendRetrieveRequestAsync ( appUserService . AZSystemAppUser , $ "{ string . Format ( DataverseQueries . ScoreParametersQuery , calculatorId ) } ", formatted : true , pageSize : 5000 ) ;
151
- response . EnsureSuccessStatusCode ( ) ;
163
+ if ( ! response . IsSuccessStatusCode )
164
+ {
165
+ var responseBody = await response . Content . ReadAsStringAsync ( ) ;
166
+ throw new Exception ( $ "GetScoreParametersAsync({ calculatorId } ):HTTP Failure: { responseBody } ") ;
167
+ }
152
168
var json = await response . Content . ReadFromJsonAsync < JsonObject > ( ) ;
153
169
var values = json [ "value" ] ? . AsArray ( ) ?? new JsonArray ( ) ;
154
170
return values . Select ( v => new ScoreParameter ( v . AsObject ( ) ) ) ;
@@ -157,7 +173,11 @@ public async Task<IEnumerable<ScoreParameter>> GetScoreParametersAsync(Guid calc
157
173
public async Task < Facility > GetFacilityDataAsync ( Guid facilityId )
158
174
{
159
175
var response = await d365WebApiService . SendRetrieveRequestAsync ( appUserService . AZSystemAppUser , $ "{ string . Format ( DataverseQueries . facilityQuery , facilityId ) } ", formatted : true , pageSize : 5000 ) ;
160
- response . EnsureSuccessStatusCode ( ) ;
176
+ if ( ! response . IsSuccessStatusCode )
177
+ {
178
+ var responseBody = await response . Content . ReadAsStringAsync ( ) ;
179
+ throw new Exception ( $ "GetFacilityDataAsync(Guid { facilityId } ): HTTP Failure: { responseBody } ") ;
180
+ }
161
181
var json = await response . Content . ReadFromJsonAsync < JsonObject > ( ) ;
162
182
return new Facility ( json ) ;
163
183
}
@@ -167,7 +187,11 @@ public async Task<Facility> GetFacilityDataAsync(Guid facilityId)
167
187
var output = new JsonObject ( ) ;
168
188
var outputObjects = new List < JsonObject > ( ) ;
169
189
var response = await d365WebApiService . SendRetrieveRequestAsync ( appUserService . AZSystemAppUser , $ "{ string . Format ( DataverseQueries . LicenseSpaces , facilityId , submittedOn ) } ", formatted : true , pageSize : 5000 ) ;
170
- response . EnsureSuccessStatusCode ( ) ;
190
+ if ( ! response . IsSuccessStatusCode )
191
+ {
192
+ var responseBody = await response . Content . ReadAsStringAsync ( ) ;
193
+ throw new Exception ( $ "GetLicenseDataAsync(Guid { facilityId } , DateTime? { submittedOn } ):HTTP Failure: { responseBody } ") ;
194
+ }
171
195
var json = await response . Content . ReadFromJsonAsync < JsonObject > ( ) ;
172
196
var values = json [ "value" ] ? . AsArray ( ) ?? new JsonArray ( ) ;
173
197
return new LicenseSpaces ( values . First ( ) . AsObject ( ) ) ;
@@ -176,7 +200,11 @@ public async Task<Facility> GetFacilityDataAsync(Guid facilityId)
176
200
public async Task < ACCBIncomeIndicator ? > GetIncomeDataAsync ( string postalCode , Guid calculatorId )
177
201
{
178
202
var response = await d365WebApiService . SendRetrieveRequestAsync ( appUserService . AZSystemAppUser , $ "{ string . Format ( DataverseQueries . IncomeDataQuery , postalCode , calculatorId ) } ", formatted : true , pageSize : 5000 ) ;
179
- response . EnsureSuccessStatusCode ( ) ;
203
+ if ( ! response . IsSuccessStatusCode )
204
+ {
205
+ var responseBody = await response . Content . ReadAsStringAsync ( ) ;
206
+ throw new Exception ( $ "GetIncomeDataAsync(string { postalCode } , Guid { calculatorId } ): HTTP Failure: { responseBody } ") ;
207
+ }
180
208
var json = await response . Content . ReadFromJsonAsync < JsonObject > ( ) ;
181
209
var values = json [ "value" ] ? . AsArray ( ) ?? new JsonArray ( ) ;
182
210
return values . Any ( ) ? new ACCBIncomeIndicator ( values . First ( ) . AsObject ( ) ) : null ;
@@ -185,7 +213,11 @@ public async Task<Facility> GetFacilityDataAsync(Guid facilityId)
185
213
public async Task < IEnumerable < ApprovedParentFee > > GetFeeDataAsync ( Guid facId )
186
214
{
187
215
var response = await d365WebApiService . SendRetrieveRequestAsync ( appUserService . AZSystemAppUser , $ "{ string . Format ( DataverseQueries . AppovedFeeDataQuery , facId ) } ", formatted : true , pageSize : 5000 ) ;
188
- response . EnsureSuccessStatusCode ( ) ;
216
+ if ( ! response . IsSuccessStatusCode )
217
+ {
218
+ var responseBody = await response . Content . ReadAsStringAsync ( ) ;
219
+ throw new Exception ( $ "GetFeeDataAsync(Guid { facId } ): HTTP Failure: { responseBody } ") ;
220
+ }
189
221
var json = await response . Content . ReadFromJsonAsync < JsonObject > ( ) ;
190
222
var values = json [ "value" ] ? . AsArray ( ) ?? new JsonArray ( ) ;
191
223
return values . Select ( v => new ApprovedParentFee ( v . AsObject ( ) ) ) ;
@@ -194,7 +226,11 @@ public async Task<IEnumerable<ApprovedParentFee>> GetFeeDataAsync(Guid facId)
194
226
public async Task < IEnumerable < FortyPercentileThresholdFee > > GetThresholdDataAsync ( Guid calculatorId )
195
227
{
196
228
var response = await d365WebApiService . SendRetrieveRequestAsync ( appUserService . AZSystemAppUser , $ "{ string . Format ( DataverseQueries . ThresholdFeeDataQuery , calculatorId ) } ", formatted : true , pageSize : 5000 ) ;
197
- response . EnsureSuccessStatusCode ( ) ;
229
+ if ( ! response . IsSuccessStatusCode )
230
+ {
231
+ var responseBody = await response . Content . ReadAsStringAsync ( ) ;
232
+ throw new Exception ( $ "GetThresholdDataAsync(Guid { calculatorId } ): HTTP Failure: { responseBody } ") ;
233
+ }
198
234
var json = await response . Content . ReadFromJsonAsync < JsonObject > ( ) ;
199
235
var values = json [ "value" ] ? . AsArray ( ) ?? new JsonArray ( ) ;
200
236
return values . Select ( v => new FortyPercentileThresholdFee ( v . AsObject ( ) ) ) ;
@@ -204,25 +240,35 @@ public async Task CreateScoreAsync(JsonObject score)
204
240
{
205
241
var jsonContent = new StringContent ( score . ToJsonString ( ) , System . Text . Encoding . UTF8 , "application/json" ) ;
206
242
var response = await d365WebApiService . SendCreateRequestAsync ( appUserService . AZSystemAppUser , $ "{ DataverseQueries . CreateScoreEndpoint } ", JsonSerializer . Serialize ( score ) ) ;
207
- response . EnsureSuccessStatusCode ( ) ;
243
+ if ( ! response . IsSuccessStatusCode )
244
+ {
245
+ var responseBody = await response . Content . ReadAsStringAsync ( ) ;
246
+ throw new Exception ( $ "CreateScoreAsync(JsonObject { score } ): HTTP Failure: { responseBody } ") ;
247
+ }
208
248
}
209
249
210
250
public async Task UpdateApplicationAsync ( Guid applicationId , JsonObject application )
211
251
{
212
252
var jsonContent = new StringContent ( application . ToJsonString ( ) , System . Text . Encoding . UTF8 , "application/json" ) ;
213
253
var response = await d365WebApiService . SendPatchRequestAsync ( appUserService . AZSystemAppUser , $ "{ string . Format ( DataverseQueries . UpdateApplicationEndpoint , applicationId ) } ", JsonSerializer . Serialize ( application ) ) ;
214
- response . EnsureSuccessStatusCode ( ) ;
215
- }
216
- public async Task UpsertApplicationScoreAsync ( string Keys , JsonObject applicationScore )
217
- {
218
- var jsonContent = new StringContent ( applicationScore . ToJsonString ( ) , System . Text . Encoding . UTF8 , "application/json" ) ;
219
- var response = await d365WebApiService . SendPatchRequestAsync ( appUserService . AZSystemAppUser , $ "{ string . Format ( DataverseQueries . UpsertApplicationScoreEndpoint , Keys ) } ", JsonSerializer . Serialize ( applicationScore ) ) ;
220
254
if ( ! response . IsSuccessStatusCode )
221
255
{
222
256
var responseBody = await response . Content . ReadAsStringAsync ( ) ;
223
- throw new Exception ( $ "HTTP Failure: { responseBody } ") ;
257
+ throw new Exception ( $ "UpdateApplicationAsync(Guid { applicationId } , JsonObject { application } ): HTTP Failure: { responseBody } ") ;
224
258
}
225
259
}
260
+ public async Task UpsertApplicationScoreAsync ( string Keys , JsonObject applicationScore )
261
+ {
262
+
263
+ var jsonContent = new StringContent ( applicationScore . ToJsonString ( ) , System . Text . Encoding . UTF8 , "application/json" ) ;
264
+ var response = await d365WebApiService . SendPatchRequestAsync ( appUserService . AZSystemAppUser , $ "{ string . Format ( DataverseQueries . UpsertApplicationScoreEndpoint , Keys ) } ", JsonSerializer . Serialize ( applicationScore ) ) ;
265
+ if ( ! response . IsSuccessStatusCode )
266
+ {
267
+ var responseBody = await response . Content . ReadAsStringAsync ( ) ;
268
+ throw new Exception ( $ "Upsert Application Score failed with request with Key = { Keys } and score Object = { applicationScore } renponse { responseBody } ") ;
269
+ }
270
+
271
+ }
226
272
public async Task UpsertApplicationScoresBatchAsync ( Dictionary < string , JsonObject > scores )
227
273
{
228
274
var batchRequests = scores . Select ( x => new PatchRequest ( $ "{ string . Format ( DataverseQueries . UpsertApplicationScoreEndpoint , x . Key ) } ", x . Value ) ) . ToList < HttpRequestMessage > ( ) ;
@@ -235,15 +281,23 @@ public async Task UpsertApplicationScoresBatchAsync(Dictionary<string, JsonObjec
235
281
public async Task < PopulationCentre ? > GetPopulationDataAsync ( string city , Guid calculatorId )
236
282
{
237
283
var response = await d365WebApiService . SendRetrieveRequestAsync ( appUserService . AZSystemAppUser , $ "{ string . Format ( DataverseQueries . PopulationCentreQuery , city , calculatorId ) } ", formatted : true , pageSize : 5000 ) ;
238
- response . EnsureSuccessStatusCode ( ) ;
284
+ if ( ! response . IsSuccessStatusCode )
285
+ {
286
+ var responseBody = await response . Content . ReadAsStringAsync ( ) ;
287
+ throw new Exception ( $ "GetPopulationDataAsyncstring { city } , Guid { calculatorId } ): HTTP Failure: { responseBody } ") ;
288
+ }
239
289
var json = await response . Content . ReadFromJsonAsync < JsonObject > ( ) ;
240
290
var values = json [ "value" ] ? . AsArray ( ) ?? new JsonArray ( ) ;
241
291
return values . Any ( ) ? new PopulationCentre ( values . First ( ) . AsObject ( ) ) : null ;
242
292
}
243
293
public async Task < SchoolDistrict ? > GetSchoolDistrictDataAsync ( string postalCode , Guid calculatorId )
244
294
{
245
295
var response = await d365WebApiService . SendRetrieveRequestAsync ( appUserService . AZSystemAppUser , $ "{ string . Format ( DataverseQueries . SchoolDistrictQuery , postalCode , calculatorId ) } ", formatted : true , pageSize : 5000 ) ;
246
- response . EnsureSuccessStatusCode ( ) ;
296
+ if ( ! response . IsSuccessStatusCode )
297
+ {
298
+ var responseBody = await response . Content . ReadAsStringAsync ( ) ;
299
+ throw new Exception ( $ "GetSchoolDistrictDataAsync(string { postalCode } , Guid { calculatorId } ): HTTP Failure: { responseBody } ") ;
300
+ }
247
301
var json = await response . Content . ReadFromJsonAsync < JsonObject > ( ) ;
248
302
var values = json [ "value" ] ? . AsArray ( ) ?? new JsonArray ( ) ;
249
303
return values . Any ( ) ? new SchoolDistrict ( values . First ( ) . AsObject ( ) ) : null ;
0 commit comments