Skip to content

fix: networkRequest no longer throws when no result matches the status code - #505

Merged
divyanshub024 merged 1 commit into
mainfrom
dv/network-request-no-match
Oct 16, 2026
Merged

divyanshub024 merged 1 commit into
mainfrom
dv/network-request-no-match

Conversation

@divyanshub024

@divyanshub024 divyanshub024 commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

Description

StacNetworkRequestParser.onCall picked the result to run with model.results.firstWhere(...) and no orElse. A networkRequest whose response status code had no matching entry in results therefore threw Bad state: No element, including in the default case where results is empty. Because onCall is async, the error escaped the try/catch in StacService.onCallFromJson, so an action fired from a button ended up as an unhandled exception.

The parser now looks up the result with where(...).firstOrNull and returns early when nothing matches: the request still runs and nothing else happens. When results is non-empty but none match, it logs a warning so a mismatched status code (for example 201 vs 200) is easy to spot. A matching result runs its action as before.

Verified locally: dart analyze reports no issues in packages/stac, and the repro from the issue no longer throws.

Related Issues

Closes #495

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Code refactor
  • Build configuration change
  • Documentation
  • Chore

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Network requests now safely return no result when the response has no status code or no configured result matches.
    • A warning is logged when a response status has no matching configured result.

…s code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b568e836-736e-4e86-aa16-3ce99a903789
📥 Commits

Reviewing files that changed from the base of the PR and between b6cfe7c and 8145fef.

📒 Files selected for processing: 1
  • packages/stac/lib/src/parsers/actions/stac_network_request/stac_network_request_parser.dart

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

📝 Walkthrough

The network request parser now returns null when the response has no status code or no configured result matches. For unmatched statuses, it logs a warning when results are configured. Matching actions still run only when the context is mounted.

Changes: Network request result handling

Layer / File(s) Summary
Handle missing and unmatched results
packages/stac/lib/src/parsers/actions/stac_network_request/stac_network_request_parser.dart
The parser returns null when the response status is missing or no configured result matches. It logs a warning for unmatched statuses when results are configured. Matching actions run only when the context is mounted.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to 8145f

The requested no-match behavior is implemented, and matching network actions continue to run. No concrete issue remains that should block merging.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: preventing networkRequest from throwing when no result matches the response status code.
Linked Issues check Passed Issue #495 requires a network request with no matching result, including an empty results list, to complete without throwing and without running a follow-up action. The parser now obtains `statusCod…
Out of Scope Changes check Passed The reviewed change is limited to stac_network_request_parser.dart. The warning for a configured but unmatched status and the early returns directly support issue #495. No unrelated implementation o…
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Full details: Linked Issues check

Explanation

Issue #495 requires a network request with no matching result, including an empty results list, to complete without throwing and without running a follow-up action. The parser now obtains statusCode, uses where(...).firstOrNull, and returns null when no result matches. A non-empty unmatched list logs a warning. A matching result still calls Stac.onCallFromJson when the context is mounted. The request execution remains before this lookup.

Full details: Out of Scope Changes check

Explanation

The reviewed change is limited to stac_network_request_parser.dart. The warning for a configured but unmatched status and the early returns directly support issue #495. No unrelated implementation or public API change is present in the reviewed diff.

Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@divyanshub024
divyanshub024 merged commit 03f669d into main Oct 16, 2026
6 checks passed
@divyanshub024
divyanshub024 deleted the dv/network-request-no-match branch October 16, 2026 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: networkRequest throws "Bad state: No element" when no result matches the status code

1 participant