Overview
In src/services/tipService.ts around line 29, responseBody is referenced in the error-path branch before it is ever assigned. The variable holding the parsed JSON is stored under a different name, so when the API returns a non-2xx status the service throws ReferenceError: responseBody is not defined instead of a meaningful error message.
Specifications
Features:
- Tip failures surface a meaningful error message to the caller rather than crashing
Tasks:
- Replace
responseBody.error with the correctly named variable (e.g. response.error after awaiting res.json())
- Add a null-safe fallback:
typeof errorBody?.error === 'string' ? errorBody.error : 'Unable to send tip.'
- Write a unit test that mocks a non-OK API response and asserts the error message is returned cleanly
Impacted Files:
src/services/tipService.ts
Acceptance Criteria
- No
ReferenceError is thrown when the tips API returns a non-2xx response
- The caller receives the server error string or the fallback message
- Existing tip success tests continue to pass
Overview
In
src/services/tipService.tsaround line 29,responseBodyis referenced in the error-path branch before it is ever assigned. The variable holding the parsed JSON is stored under a different name, so when the API returns a non-2xx status the service throwsReferenceError: responseBody is not definedinstead of a meaningful error message.Specifications
Features:
Tasks:
responseBody.errorwith the correctly named variable (e.g.response.errorafter awaitingres.json())typeof errorBody?.error === 'string' ? errorBody.error : 'Unable to send tip.'Impacted Files:
src/services/tipService.tsAcceptance Criteria
ReferenceErroris thrown when the tips API returns a non-2xx response