submitNpsResponse method

Future<void> submitNpsResponse({
  1. required String token,
  2. required int score,
  3. String? comment,
})

Submits an NPS survey response to the server. Failures are swallowed — the thank-you screen is shown regardless of network outcome (per spec).

There is no retry here: _RelevaHttpClient does it, with the right carve-outs and its own log line. This used to retry once more on top, which multiplies rather than adds — NpsOverlayWidget awaits this call behind a disabled spinner, so a nested budget against a 5xx-ing server would hold that spinner for twice the client's own worst case.

Implementation

Future<void> submitNpsResponse({
  required String token,
  required int score,
  String? comment,
}) async {
  assert(score >= 0 && score <= 10, 'NPS score must be 0–10');
  final storage = HiveStorageService.instance;
  final body = {
    'profileId': await storage.getProfileId(),
    'deviceId': await storage.getDeviceId(),
    'sessionId': await SessionService.instance.getSessionId(),
    'score': score,
    if (comment != null && comment.isNotEmpty) 'comment': comment,
  };

  Future<void> doPost() async {
    final response = await http.post(
      Uri.parse('${_getEndpoint()}/api/v0/nps/${Uri.encodeComponent(token)}/submissions'),
      headers: {
        'content-type': 'application/json',
        'authorization': 'Bearer $_accessToken',
      },
      body: jsonEncode(body),
    );
    if (response.statusCode != 202) {
      throw Exception(
          'NPS submit error: ${response.statusCode} - ${response.body}');
    }
  }

  try {
    await doPost();
  } catch (e) {
    debugPrint('[Releva] NPS submission failed (silent): $e');
  }
}