Skip to content

Three services reimplement error extraction with different shapes: outages, SLA, and bulk import drift independently #405

Description

@usmanimamu17-create

Problem

Error-to-message extraction exists three times with three different behaviors:

  • handleApiError in src/services/outages.ts — handles detail (string) and message.
  • extractErrorMessage in src/services/sla.ts — reads message only (broken for FastAPI — companion issue).
  • extractErrorMessage in src/services/bulkImportService.ts — reads message only.
  • normalizeApiError in src/lib/errors.ts — reads detail (string or array), message, correlation ids — a fourth implementation for the axios path.

Consequences:

  • Behavior varies by service: an outages failure shows the server reason; an SLA failure shows a generic fallback; the axios interceptor normalizes yet another way — the same backend error renders differently depending on which service threw it.
  • Fixes are duplicated: any improvement (detail-array handling, field-level mapping, correlation ids) must be re-implemented per copy or silently missed.
  • The duplication is invisible: each helper is private to its module, so there is no single place to audit "how do we render API errors".

Root cause

The error helpers were written per-service before a shared convention existed.

Why this is architecturally hard

  1. The consolidation target is a single extractApiErrorMessage (string/array detail, message, fallback) that normalizeApiError also delegates to — but the axios interceptor's version returns a structured NormalizedApiError (kind, correlationId) while the service helpers return plain strings; unifying the return shape is a type decision.
  2. Service callers use the string for UI copy; changing the shared helper's output must keep every call site's rendering working (some concatenate the message into longer strings).
  3. Tests exist per service (bulk-import-view, payments-view, sla-related); the consolidation must keep their assertions meaningful by testing the shared helper once plus per-service fallback text.

Proposed design

Extract a shared error helper (and, for the axios path, make normalizeApiError use it), keep per-service fallback text as parameters, and move the error-mapping tests to the shared module with per-service spot checks.

Acceptance criteria

Service

  • All services surface API errors through the same helper.
  • Per-service fallback text is preserved.

Tests

  • The shared helper has table-driven tests; each service has a spot check.
  • Existing service tests pass.

Out of scope

Field-level 422 mapping (tracked separately).

Getting started

npm test

Good first files to read: src/services/outages.ts, src/services/sla.ts, src/services/bulkImportService.ts, src/lib/errors.ts.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardStellar Waveissue-trackingThird CampaignCampaign: Third Campaignarea/apiImported campaign issue labelpriority/mediumImported campaign issue label

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions