Skip to content

fix: the Response from DioError could return null from the data property but String is expected in ParseNetworkResponse #775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from

Conversation

Nidal-Bakir
Copy link
Member

@Nidal-Bakir Nidal-Bakir commented Jul 9, 2022

New Pull Request Checklist

Issue Description

The response from dio error object could have a null data property

Related issue: #774

Approach

Add null aware operator ??:

on dio.DioError catch (error) {
      return ParseNetworkByteResponse(
        data: error.response?.data ?? _fallbackErrorData,
        statusCode: error.response!.statusCode!,
      );
    }

TODOs before merging

All set

  • Add tests
  • Add changes to documentation (guides, repository pages, in-code descriptions)
  • A changelog entry

@parse-github-assistant
Copy link

parse-github-assistant bot commented Jul 9, 2022

Thanks for opening this pull request!

  • 🎉 We are excited about your hands-on contribution!

@Nidal-Bakir Nidal-Bakir changed the title fix bug#774: null is not a subtype of String fix: bug#774: null is not a subtype of String Jul 9, 2022
@mtrezza
Copy link
Member

mtrezza commented Jul 9, 2022

Could you please replace the PR title with fix: <summary of what the issue is>; I assume the related issue is #775, I have added this to your PR description.

@mtrezza mtrezza linked an issue Jul 9, 2022 that may be closed by this pull request
4 tasks
Copy link
Member

@mtrezza mtrezza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test for this?

@Nidal-Bakir Nidal-Bakir changed the title fix: bug#774: null is not a subtype of String fix: The Response from DioError could return null from the data property but String is expected in ParseNetworkResponse Jul 10, 2022
@parse-github-assistant
Copy link

I will reformat the title to use the proper commit message syntax.

@parse-github-assistant parse-github-assistant bot changed the title fix: The Response from DioError could return null from the data property but String is expected in ParseNetworkResponse fix: the Response from DioError could return null from the data property but String is expected in ParseNetworkResponse Jul 10, 2022
@Nidal-Bakir
Copy link
Member Author

Nidal-Bakir commented Jul 10, 2022

Sure, but I can not find a way to mock the _ParseDioClient class to fake the DioError.
I was thinking of adding a typedef like this:

typedef ParseDioClientForMockTest = _ParseDioClient;

so I can create a mock for it and inject it in the constructor of ParseDioClient maybe like this:

  ParseDioClient({
      bool sendSessionId = false,
      SecurityContext? securityContext,
      _ParseDioClient? parseDioClientForMockTest,
      }) {
    _client = parseDioClientForMockTest ??
        _ParseDioClient(
          sendSessionId: sendSessionId,
          securityContext: securityContext,
        );
  }

But this requires the 'nonfunction-type-aliases' language feature to be enabled, so we need to set the minimum SDK constraint to 2.16.0 or higher.

Do you have any suitable way to do this?

@Nidal-Bakir Nidal-Bakir requested a review from mtrezza July 19, 2022 10:42
@mtrezza mtrezza requested review from a team and removed request for mtrezza July 19, 2022 12:56
@codecov
Copy link

codecov bot commented Jul 19, 2022

Codecov Report

Base: 10.26% // Head: 10.08% // Decreases project coverage by -0.18% ⚠️

Coverage data is based on head (2b3b05d) compared to base (14be107).
Patch coverage: 0.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #775      +/-   ##
==========================================
- Coverage   10.26%   10.08%   -0.19%     
==========================================
  Files          49       47       -2     
  Lines        2815     2817       +2     
==========================================
- Hits          289      284       -5     
- Misses       2526     2533       +7     
Impacted Files Coverage Δ
...ackages/dart/lib/src/network/parse_dio_client.dart 0.00% <0.00%> (ø)
packages/dart/lib/src/network/options.dart 0.00% <0.00%> (-50.00%) ⬇️
...ackages/dart/lib/src/network/parse_live_query.dart 0.00% <0.00%> (-0.92%) ⬇️
packages/flutter/lib/parse_server_sdk.dart 8.77% <0.00%> (ø)
packages/dart/lib/src/objects/parse_file.dart 0.00% <0.00%> (ø)
packages/dart/lib/src/objects/parse_user.dart 0.00% <0.00%> (ø)
packages/dart/lib/src/objects/parse_file_web.dart 0.00% <0.00%> (ø)
packages/dart/lib/src/objects/parse_file_base.dart 0.00% <0.00%> (ø)
...ckages/dart/lib/src/network/parse_http_client.dart 5.12% <0.00%> (ø)
... and 6 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@mtrezza
Copy link
Member

mtrezza commented Jul 28, 2022

@parse-community/flutter-sdk-review what do you think, is this ready for merge?

@Nidal-Bakir Nidal-Bakir closed this by deleting the head repository Oct 23, 2022
@mtrezza
Copy link
Member

mtrezza commented Oct 23, 2022

@Nidal-Bakir any particular reason for closing this?

@mtrezza
Copy link
Member

mtrezza commented Oct 23, 2022

@parse-community/flutter-sdk-review should this PR be merged?

@Nidal-Bakir
Copy link
Member Author

Nidal-Bakir commented Oct 24, 2022

@mtrezza
I'm sorry, I did not mean to close the PR!
I did not know that if I deleted the forked repository from my account all my PR would be closed.

I was testing some things in my forked repository so I got to a point where I just needed to start from the beginning. so found it easier to just delete the repository and start all over again.

@mtrezza mtrezza reopened this Oct 24, 2022
@mtrezza
Copy link
Member

mtrezza commented Oct 24, 2022

I've reopened, thanks for clarifying

@@ -31,7 +31,9 @@ class ParseDioClient extends ParseClient {
data: dioResponse.data!, statusCode: dioResponse.statusCode!);
} on dio.DioError catch (error) {
return ParseNetworkResponse(
data: error.response?.data, statusCode: error.response!.statusCode!);
data: error.response?.data ?? _fallbackErrorData,
statusCode: error.response!.statusCode!,
Copy link
Member

@mbfakourii mbfakourii Nov 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran this code without internet connection and got null error in statusCode!
I suggest you change the code like this

return ParseNetworkResponse(
  data: error.response?.data ?? _fallbackErrorData,
  statusCode: error.response?.statusCode! ?? ParseError.otherCause,
);

@Nidal-Bakir
Copy link
Member Author

Nidal-Bakir commented Feb 24, 2023

Reopening in a different PR because I lost all the progress and the reference of these changes.
The new PR pull/825

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.

Type 'Null' is not a subtype of type 'String'
3 participants