You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Follow-up: replace the regex-based 401/403 heuristic in
`mapIpfsError` with an explicit `httpStatus` field so the
classification is data-driven and the rate-limit / file-size / token
failures each route to the correct RFC 7807 catalog row.
**Breaking**: rate-limit failures now map to `429 RATE_LIMITED` instead
of the previous mis-classified `401 UNAUTHORIZED`. Callers that
relied on the heuristic artifact (the rate-limit assertion in
`tests/middleware/auth.test.js` was migrated that way during the
first PR) are updated to expect `RateLimitError`/429.
**Backward compatible**: `createIpfsError(message, operation, details)`
still works \u2014 the new 4th param `httpStatus` defaults to `null` and
`mapIpfsError` falls back to a frozen dispatch table keyed by
`operation`. All 25 other `createIpfsError` call-sites in
`services/ipfs.js` and `routes/content.js` continue to compile and
resolve to the same RFC 7807 status they did before (auth \u2192 401,
validation \u2192 400, init \u2192 503, get* \u2192 404, upload/pin* \u2192 500).
**Other fixes folded in**:
- `validateFileSize` no longer blanket-maps every IPFS error to 413.
File-size overruns stay 413; other ipfs validation failures bubble
up as 400 unless overridden.
- `optionalIpfsAuth` silent-fallback for invalid tokens / unexpected
errors preserved exactly \u2014 the only error class that surfaces is
explicit 403, no more `/permission/i` regex.
- `OPERATION_STATUS_MAP` exported for unit testing.
**Tests** (`backend/tests/utils/ipfsUtils.test.js`):
- `createIpfsError` 3-arg / 4-arg backward-compat
- `mapIpfsError` dispatch for each documented status (400/401/403/404/\n413/429/503)
- Fallback-table coverage for every operation in `OPERATION_STATUS_MAP`\n- Unknown status / unknown operation \u2192 `InternalError(500)`\n- Non-Ipfs / null / undefined \u2192 `AuthError(401)` preserved\n\n`backend/tests/middleware/auth.test.js` updated:\n- Rate-limit assertion moved from stale `AuthError(401)` \u2192\n `RateLimitError(429)` (matches the new contract).\n- Over-engineered `validateFileSize` test (jest.resetModules +\n `process.env` overrides) replaced with a clean `jest.isolateModules`\n + `jest.doMock` block asserting the payload AppError class.\n- `optionalIpfsAuth` `ForbiddenError` test replaced with a real\n `supertest(app).get('/')` drive against `optionalIpfsAuth \u2192\n errorHandler` asserting `res.body.code === 'FORBIDDEN'` and\n `res.headers['content-type'] === 'application/problem+json'`.\n\nRefs: #254, #127.
0 commit comments