Skip to content

[Bug] responseBody used before declaration in tipService.ts causes ReferenceError on API errors #703

Description

@RUKAYAT-CODER

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

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programbugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions