Commit d7efd20
authored
Cleanup HTTP client headers and testing code (#55)
This cleans up the abstraction for HTTP request header configuration in
the various API clients by merging headers instead of overwriting them.
This also cleans up some old HTTP testing code which resolves some
potential auth token refresh issues in TDEI calls.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary
This PR refactors HTTP client header handling across the frontend
services to merge headers instead of overwriting them, and removes
legacy testing code. The changes introduce type-safe configurations for
HTTP requests and centralize header management in the base HTTP client.
## Changes by File
### services/http.ts
- Added exported types `FetchConfig` (based on `RequestInit` with
optional typed headers) and `HttpBody` (union of `BodyInit | object`)
- Refactored `BaseHttpClient._send` pipeline to merge default headers
with per-request headers from `FetchConfig`
- Improved body handling: FormData strips the `Content-Type` header to
allow browser defaults, and JSON stringification is determined by both
resolved `Content-Type` and runtime body type
- Removed the `_sendTest` helper method, simplifying the test code
cleanup
- Updated all request method signatures (`_get`, `_post`, `_put`,
`_patch`, `_delete`) to use the new `FetchConfig` type
### services/osm.ts
- Updated method signature for `_send` override to use typed `HttpBody`
and `FetchConfig` parameters
- Changed default `Accept` header from `text/plain` to `*/*`
- Refactored `provisionUser` to pass JSON objects directly with
`Content-Type: application/json` instead of manually stringifying
- Removed per-request spreading of internal `_requestHeaders` across
multiple methods (workspace/element/node/way retrieval, changeset
operations, notes search, export)
- Centralized auth handling: `_send` override now calls
`tryRefreshAuth()` before sending and re-applies auth headers via
`#setAuthHeader()`, then merges `credentials: 'include'` with provided
config
### services/tdei.ts
- Updated `_send` override signatures in both `TdeiClient` and
`TdeiUserClient` to use typed `HttpBody` and `FetchConfig` parameters
- Replaced `_sendTest` calls with `_get` for dataset downloads
(`downloadOswDataset`, `downloadPathwaysDataset`)
- Removed explicit per-request `Authorization` header injection from
upload methods
- Simplified dataset conversion flow by removing manual
`Accept`/`Authorization` header handling
- Preserved refresh-before-send behavior in both client classes
### services/workspaces.ts
- Updated `WorkspacesClient._send` method signature to use typed
`HttpBody` and `FetchConfig` parameters instead of loose types
- Runtime behavior preserved: auth refresh, header setting, and error
wrapping remain unchanged
## Key Improvements
- Centralized header merging logic prevents accidental header
overwriting
- Type-safe HTTP configuration across all services
- Removal of `_sendTest` test helper reduces code duplication
- Consistent auth token refresh handling, addressing potential token
refresh issues in TDEI calls
<!-- review_stack_entry_start -->
[](https://app.coderabbit.ai/change-stack/TaskarCenterAtUW/workspaces-frontend/pull/55?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)
<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->4 files changed
Lines changed: 114 additions & 82 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
1 | 7 | | |
2 | 8 | | |
3 | 9 | | |
| |||
25 | 31 | | |
26 | 32 | | |
27 | 33 | | |
28 | | - | |
| 34 | + | |
29 | 35 | | |
30 | 36 | | |
31 | 37 | | |
32 | | - | |
| 38 | + | |
33 | 39 | | |
34 | 40 | | |
35 | 41 | | |
36 | | - | |
| 42 | + | |
37 | 43 | | |
38 | 44 | | |
39 | 45 | | |
40 | | - | |
| 46 | + | |
41 | 47 | | |
42 | 48 | | |
43 | 49 | | |
44 | | - | |
| 50 | + | |
45 | 51 | | |
46 | 52 | | |
47 | 53 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
66 | 65 | | |
67 | 66 | | |
68 | | - | |
69 | | - | |
| 67 | + | |
| 68 | + | |
70 | 69 | | |
71 | | - | |
| 70 | + | |
72 | 71 | | |
73 | 72 | | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
79 | 89 | | |
80 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
81 | 94 | | |
82 | 95 | | |
83 | 96 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
5 | 10 | | |
6 | 11 | | |
7 | 12 | | |
| |||
14 | 19 | | |
15 | 20 | | |
16 | 21 | | |
17 | | - | |
18 | 22 | | |
19 | 23 | | |
20 | 24 | | |
| |||
207 | 211 | | |
208 | 212 | | |
209 | 213 | | |
210 | | - | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
211 | 217 | | |
212 | 218 | | |
213 | 219 | | |
| |||
234 | 240 | | |
235 | 241 | | |
236 | 242 | | |
237 | | - | |
238 | | - | |
| 243 | + | |
| 244 | + | |
239 | 245 | | |
240 | 246 | | |
241 | 247 | | |
| |||
286 | 292 | | |
287 | 293 | | |
288 | 294 | | |
289 | | - | |
290 | 295 | | |
291 | 296 | | |
292 | 297 | | |
| |||
301 | 306 | | |
302 | 307 | | |
303 | 308 | | |
304 | | - | |
305 | 309 | | |
306 | 310 | | |
307 | 311 | | |
| |||
319 | 323 | | |
320 | 324 | | |
321 | 325 | | |
322 | | - | |
323 | 326 | | |
324 | 327 | | |
325 | 328 | | |
| |||
337 | 340 | | |
338 | 341 | | |
339 | 342 | | |
340 | | - | |
341 | 343 | | |
342 | 344 | | |
343 | 345 | | |
| |||
348 | 350 | | |
349 | 351 | | |
350 | 352 | | |
351 | | - | |
| 353 | + | |
352 | 354 | | |
353 | 355 | | |
354 | 356 | | |
| |||
374 | 376 | | |
375 | 377 | | |
376 | 378 | | |
377 | | - | |
378 | 379 | | |
379 | 380 | | |
380 | 381 | | |
| |||
401 | 402 | | |
402 | 403 | | |
403 | 404 | | |
404 | | - | |
405 | 405 | | |
406 | 406 | | |
407 | 407 | | |
| |||
427 | 427 | | |
428 | 428 | | |
429 | 429 | | |
430 | | - | |
| 430 | + | |
431 | 431 | | |
432 | 432 | | |
433 | 433 | | |
| |||
441 | 441 | | |
442 | 442 | | |
443 | 443 | | |
444 | | - | |
445 | 444 | | |
446 | 445 | | |
447 | 446 | | |
| |||
468 | 467 | | |
469 | 468 | | |
470 | 469 | | |
471 | | - | |
472 | | - | |
473 | | - | |
474 | | - | |
| 470 | + | |
475 | 471 | | |
476 | 472 | | |
477 | 473 | | |
| |||
484 | 480 | | |
485 | 481 | | |
486 | 482 | | |
487 | | - | |
488 | 483 | | |
489 | 484 | | |
490 | 485 | | |
| |||
497 | 492 | | |
498 | 493 | | |
499 | 494 | | |
500 | | - | |
501 | 495 | | |
502 | 496 | | |
503 | 497 | | |
| |||
510 | 504 | | |
511 | 505 | | |
512 | 506 | | |
513 | | - | |
514 | 507 | | |
515 | 508 | | |
516 | 509 | | |
| |||
525 | 518 | | |
526 | 519 | | |
527 | 520 | | |
528 | | - | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
529 | 527 | | |
530 | 528 | | |
531 | 529 | | |
532 | 530 | | |
533 | | - | |
534 | | - | |
535 | | - | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
536 | 534 | | |
537 | 535 | | |
538 | | - | |
| 536 | + | |
| 537 | + | |
539 | 538 | | |
540 | 539 | | |
541 | 540 | | |
| |||
0 commit comments