Skip to content
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

DioError [DioErrorType.response]: Http status error [500] #1171

Closed
DhavalRKansara opened this issue May 26, 2021 · 41 comments
Closed

DioError [DioErrorType.response]: Http status error [500] #1171

DhavalRKansara opened this issue May 26, 2021 · 41 comments

Comments

@DhavalRKansara
Copy link

DhavalRKansara commented May 26, 2021

With Dio 4.0.0 I am getting the below error with post request and the same post request working fine with the postman.

Code:

    Map<String, dynamic> headers = <String, dynamic>{};

    if (_token != null && _token.isNotEmpty) {
      headers['Authorization'] = 'Bearer $_token';
    }

    var dio = Dio(BaseOptions(
      baseUrl: 'https://myurl.com/' + '/api',
      connectTimeout: 50000,
      receiveTimeout: 50000,
      contentType: 'application/json',
      headers: headers,
    ));
    dio.interceptors.add(LogInterceptor(
        requestBody: logEnabled(),
        responseBody: logEnabled(),
        request: logEnabled(),
        requestHeader: logEnabled(),
        responseHeader: logEnabled()));

Error:

DioError [DioErrorType.response]: Http status error [500]
#0      DioMixin.assureDioError (package:dio/src/dio_mixin.dart:819:20)
#1      DioMixin._dispatchRequest (package:dio/src/dio_mixin.dart:678:13)
<asynchronous suspension>
#2      DioMixin.fetch.<anonymous closure>.<anonymous closure> (package:dio/src/dio_mixin.dart)
<asynchronous suspension>
@aboutlan
Copy link

Hi, @DhavalRKansara Did you call any print exception.toString() method in catch body?

@Rammehar
Copy link

With Dio 4.0.0 I am getting the below error with post request and the same post request working fine with the postman.

Code:

    Map<String, dynamic> headers = <String, dynamic>{};

    if (_token != null && _token.isNotEmpty) {
      headers['Authorization'] = 'Bearer $_token';
    }

    var dio = Dio(BaseOptions(
      baseUrl: 'https://testportal.medpharmservices.com:4437/' + '/api',
      connectTimeout: 50000,
      receiveTimeout: 50000,
      contentType: 'application/json',
      headers: headers,
    ));
    dio.interceptors.add(LogInterceptor(
        requestBody: logEnabled(),
        responseBody: logEnabled(),
        request: logEnabled(),
        requestHeader: logEnabled(),
        responseHeader: logEnabled()));

Error:

DioError [DioErrorType.response]: Http status error [500]
#0      DioMixin.assureDioError (package:dio/src/dio_mixin.dart:819:20)
#1      DioMixin._dispatchRequest (package:dio/src/dio_mixin.dart:678:13)
<asynchronous suspension>
#2      DioMixin.fetch.<anonymous closure>.<anonymous closure> (package:dio/src/dio_mixin.dart)
<asynchronous suspension>

I am facing same issue

@dokind
Copy link

dokind commented May 31, 2021

same here

code :
[VERBOSE-2:ui_dart_state.cc(199)] Unhandled Exception: DioError [DioErrorType.response]: Http status error [404]
#0 DioMixin.assureDioError
package:dio/src/dio_mixin.dart:819
#1 DioMixin._dispatchRequest
package:dio/src/dio_mixin.dart:678

#2 DioMixin.fetch.. (package:dio/src/dio_mixin.dart)
package:dio/src/dio_mixin.dart:1

#0 DioMixin.fetch.
package:dio/src/dio_mixin.dart:618
#1 _rootRunBinary (dart:async/zone.dart:1378:47)
#2 _CustomZone.runBinary (dart:async/zone.dart:1272:19)

@assylman
Copy link

I have same issue. Any updates on 14 June 2021???

@Gagan5278
Copy link

any success please??

@MuhammadSufyanMalik
Copy link

Unfortunately, I have the same issue.
Whereas I am also using the same post method for registration it is working perfectly.
How it is possible?
Does anyone have any idea?

@papakay
Copy link

papakay commented Jul 4, 2021

I'm also experiencing similar issue!

@Rammehar
Copy link

Rammehar commented Jul 5, 2021

not facing any issue right now, previously I have faced http 500 error because of passing wrong uri

@VocsyDikshit
Copy link

Have you guys solved the Error? about Dio 500 server error

@khaledeltarabily
Copy link

khaledeltarabily commented Jul 7, 2021

the same here

code :

 flutter: onError: DioError [DioErrorType.response]: Http status error [401]
#0      DioMixin.assureDioError (package:dio/src/dio_mixin.dart:819:20)
#1      DioMixin._dispatchRequest (package:dio/src/dio_mixin.dart:678:13)
<asynchronous suspension>
#2      DioMixin.fetch.<anonymous closure>.<anonymous closure> (package:dio/src/dio_mixin.dart)
<asynchronous suspension>

@huu-voyager
Copy link

huu-voyager commented Jul 15, 2021

the same here
flutter: #0 DioMixin.assureDioError (package:dio/src/dio_mixin.dart:819:20)
flutter: #1 DioMixin._dispatchRequest (package:dio/src/dio_mixin.dart:678:13)
flutter:
flutter: #2 DioMixin.fetch.. (package:dio/src/dio_mixin.dart)
flutter:

@Rammehar
Copy link

Rammehar commented Jul 16, 2021 via email

@nkulic
Copy link

nkulic commented Jul 23, 2021

Yes we have solved it

On Tue, Jul 6, 2021, 2:25 PM Dikshit Kanani @.***> wrote: Have you guys solved the Error? about Dio 500 server error — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#1171 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACEQCNYVNFWLLF6W642R3KTTWLAGJANCNFSM45RL2HVA .

How did you solved it?

I expect error to be handled when catching it in try/catch block, but for some reason it is not as I'm getting error:

I/flutter (27376): #0      DioMixin.assureDioError          package:dio/src/dio_mixin.dart:819
I/flutter (27376): #1      DioMixin._dispatchRequest      package:dio/src/dio_mixin.dart:678
I/flutter (27376): <asynchronous suspension>
I/flutter (27376): #2      DioMixin.fetch.<anonymous closure>.<anonymous closure> (package:dio/src/dio_mixin.dart)

@tiendunghk
Copy link

same here

@ksroo
Copy link

ksroo commented Aug 1, 2021

yes some error here

@kobe-pedrolucas
Copy link

same here

1 similar comment
@SEFkiss
Copy link

SEFkiss commented Sep 2, 2021

same here

@SEFkiss
Copy link

SEFkiss commented Sep 2, 2021

`getHotels() async {
setState(() {
isDataLoading = true;
});

try {
  final response = await _dio
      .get('https://run.mocky.io/v3/ac888dc5-d193-4700-b12c-abb43e2893012');
  hotels = response.data
      .map<HotelShortInfo>((item) => HotelShortInfo.fromJson(item))
      .toList();
} on DioError catch (error) {
  setState(() {
    isLoadingError = true;
  });
  print('Error loading');
}

setState(() {
  isDataLoading = false;
});

}`

Dont catch 404

@hussamDana92
Copy link

same here

@yuanzhiying
Copy link

When I update dio to 4.0.0, some post requests response 500 error and some works fine.

[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: DioError [DioErrorType.response]: Http status error [500]
#0      DioMixin.assureDioError (package:dio/src/dio_mixin.dart:819:20)
#1      DioMixin._dispatchRequest (package:dio/src/dio_mixin.dart:678:13)
<asynchronous suspension>
#2      DioMixin.fetch.<anonymous closure>.<anonymous closure> (package:dio/src/dio_mixin.dart)
<asynchronous suspension>

#0      DioMixin.fetch.<anonymous closure> (package:dio/src/dio_mixin.dart:618:7)
#1      _rootRunBinary (dart:async/zone.dart:1452:47)
#2      _CustomZone.runBinary (dart:async/zone.dart:1342:19)
#3      _FutureListener.handleError (dart:async/future_impl.dart:175:22)
#4      Future._propagateToListeners.handleError (dart:async/future_impl.dart:779:47)
#5      Future._propagateToListeners (dart:async/future_impl.dart:800:13)
#6      Future._completeError (dart:async/future_impl.dart:610:5)
#7      _SyncCompleter._completeError (dart:async/future_impl.dart:61:12)
#8      _Completer.completeError (dar<…>

I solved the error by passing {} to data parameters.

before dio 4.0.0:

var dio = Dio();
var data = {'city-id': '371000000000'};
var response = await dio.post(url1, data: null, options: Options(headers: data));

dio 4.0.0:

var dio = Dio();
var data = {'city-id': '371000000000'};
var response = await dio.post(url1, data: {}, options: Options(headers: data));

@toanphung
Copy link

Runner[85962:9567168] flutter: DioError [DioErrorType.response]: Http status error [500] #0 DioMixin.assureDioError (package:dio/src/dio_mixin.dart:819:20) #1 DioMixin._dispatchRequest (package:dio/src/dio_mixin.dart:678:13) <asynchronous suspension> #2 DioMixin.fetch.<anonymous closure>.<anonymous closure> (package:dio/src/dio_mixin.dart) <asynchronous suspension> 2021-09-29 10:10:17.508929+0700 Runner[85962:9567168] flutter:

I have same issue. And when I upload app to Apple rejected :(

@aboutmydreams
Copy link

same problem:
DioError (DioError [DioErrorType.other]: HttpException: , uri = http://baidu.com/webhook_app
#0 DioMixin.assureDioError (package:dio/src/dio_mixin.dart:819:20)
#1 DioMixin._dispatchRequest (package:dio/src/dio_mixin.dart:678:13)

#2 DioMixin.fetch.. (package:dio/src/dio_mixin.dart)

)

@aboutmydreams
Copy link

同样的问题: DioError (DioError [DioErrorType.other]: HttpException: , uri = http://baidu.com/webhook_app #0 DioMixin.assureDioError (package:dio/src/dio_mixin.dart:819:20) #1 DioMixin. _dispatchRequest (package:dio/src/dio_mixin.dart:678:13) #2 DioMixin.fetch.. (package:dio/src/dio_mixin.dart) )

i find my issue due to vpn havent work

@jinseokoh
Copy link

I've experienced the same error. After looking at the server side error logs, I've found out that some of request headers from Dio was missing like content-type, token, etc. Somehow Dio seemed to have a problem in dispatching request while it fetches data from interceptors.

A quick and dirty solution I came up with was wrapping the request logic in a Future.delayed() as follows. In my case context.read<SomeCubit>().load() initiates API calls.

goes from

  @override
  void initState() {
    super.initState();
    context.read<SomeCubit>().load();
  }

to

  @override
  void initState() {
    super.initState();
    Future.delayed(const Duration(milliseconds: 300), () {
      context.read<SomeCubit>().load();
    });
  }

@a7md0
Copy link

a7md0 commented Nov 12, 2021

Same issue here, whenever my API is returning 4xx errors (e.g., 401) I receive this uncaught exception (even though I have the call in try/catch block)

Exception has occurred.
DioError (DioError [DioErrorType.response]: Http status error [401]
#0      DioMixin.assureDioError (package:dio/src/dio_mixin.dart:821:20)
#1      DioMixin._dispatchRequest (package:dio/src/dio_mixin.dart:678:13)
<asynchronous suspension>
#2      DioMixin.fetch.<anonymous closure>.<anonymous closure> (package:dio/src/dio_mixin.dart)
<asynchronous suspension>
)

While debugging, if I skipped this uncaught exception it continue to my catch block which is weird

dio version 4.0.1

@wendux
Copy link
Contributor

wendux commented Nov 19, 2021

try 4.0.3

@wendux wendux closed this as completed Nov 29, 2021
@HoangPhuc2001
Copy link

NewDocViewModel.NoSuchMethodError: Class 'String' has no instance getter 'statusCode'.
Receiver: "Http status error [500]"
Tried calling: statusCode
This is my log, hope someone can give me a solution to this problem, thanks.

@rohankandwal
Copy link

Getting same issue 4.0.6 as well, why errors are not getting caught in try catch?

@VisalSUOS
Copy link

VisalSUOS commented Sep 5, 2022

if (err.response?.statusCode == 401) {
try {
await Dio()
.post(
"/mobile/auth/refresh-token".addBaseUrl(),
data: jsonEncode(
{
"refreshToken": StorageService.getRefreshToken(),
"accessToken": StorageService.getAccessToken(),
},
),
)
.then((value) async {

/flutter ( 6818): DioError [DioErrorType.response]: Http status error [500]
I/flutter ( 6818): Source stack:
I/flutter ( 6818): #0 DioMixin.fetch (package:dio/src/dio_mixin.dart:488:35)
I/flutter ( 6818): #1 DioMixin.request (package:dio/src/dio_mixin.dart:483:12)
I/flutter ( 6818): #2 DioMixin.post (package:dio/src/dio_mixin.dart:97:12)
I/flutter ( 6818): #3 instanceDio. (package:wallet79mobile/repository/service/base_http_request.dart:41:28)
I/flutter ( 6818): #4 instanceDio. (package:wallet79mobile/repository/service/base_http_request.dart:35:18)
I/flutter ( 6818): #5 _InterceptorWrapperMixin.onError (package:dio/src/interceptor.dart:304:16)
I/flutter ( 6818): #6 DioMixin.fetch._errorInterceptorWrapper... (package:dio/src/dio_mixin.dart:574:28)
I/flutter ( 6818): #7 DioMixin.checkIfNeedEnqueue (package:dio/src/dio_mixin.dart:789:22)
I/flutter ( 6818): #8 DioMixin.fetch._errorInterceptorWrapper.. (package:dio/src/dio_mixin.dart:572:22)
I/flutter ( 6818): #9 new Future. (dart:async/future.dart:252:37)
I/flutter ( 6818): #10 _rootRun (dart:async/z

I got same issue ^4.0.6

@davidvalari
Copy link

I found something. If you have an interceptor onError handler, it seems to be all falling back there so we basically can't catch it within the call. Removing the global onError handler solves it for me

@nimra123-456
Copy link

I have the same issue [DioError [DioErrorType.response]: Http status error [500]
Have anyone solved?

@geoapis-ti
Copy link

Same here. I have a post request working fine on 4.0.6 but when I upgrade to 5 suddenly nothing posts anymore, I keep getting 500 errors. If it worked with v4 the. definitely it's not my apis

@a1ssat
Copy link

a1ssat commented Feb 20, 2023

@cfug requests working fine on 4.0.6 but when I upgrade to 5, i got this :

╔╣ DioError ║ Status: 400 Bad Request
flutter: ║  https://api.********.com
flutter: ╚══════════════════════════════════════════════════════════════════════════════════════════╝
flutter: ╔ DioErrorType.badResponse
flutter: ║ POST body missing, invalid Content-Type, or JSON object has no keys.
flutter: ╚══════════════════════════════════════════════════════════════════════════════════════════╝

@naushadhusain
Copy link

With dio: ^5.0.3 I am getting the below error with post request and the same post request working fine with the postman.

@felimoles
Copy link

felimoles commented Sep 29, 2023

add

try{
 //dio method
}catch (e){
print(e);
}

@Shvet
Copy link

Shvet commented Dec 7, 2023

Anyone found solution i have same issue, I tried with versions 4.0.0-prev2, 4.0.6, 5.4.0. But none of these version worked. I have few apis which works while others don't. But same apis works with postman.

@kuhnroyal
Copy link
Member

@Shvet 500 is a server error, dio does not create that error our of nowhere. Maybe some default header is missing that is automatically added by postman. Create a reproducible sample and open a new issue.

@Pradeep12nap

This comment has been minimized.

@Shvet
Copy link

Shvet commented Dec 15, 2023

@Shvet 500 is a server error, dio does not create that error our of nowhere. Maybe some default header is missing that is automatically added by postman. Create a reproducible sample and open a new issue.

fixed it was server side issue!
Thank you for your reply!

@ranjithbobby89
Copy link

Anyone found solution i have same issue, I tried with versions 4.0.0-prev2, 4.0.6, 5.4.0. But none of these version worked. I have few apis which works while others don't. But same apis works with postman.

Use

dio.interceptors.add(InterceptorsWrapper(onError: (DioError e, handler) {
return handler.reject(e);
}));

Then ,You can catch in catch block so handle it by internal.

@saidelouardy
Copy link

Future homescreenAPI() async {
var map;
SharedPreferences prefs = await SharedPreferences.getInstance();
username = (prefs.getString(UD_user_name) ?? "");
userid = (prefs.getString(UD_user_id) ?? "");
islogin = prefs.getString(UD_user_is_login_required);
profileimage = (prefs.getString(UD_user_profileimage) ?? "");
session_id = (prefs.getString(UD_user_session_id) ?? "");
print("user" + userid);
print("session" + session_id);
try {
if (userid != "") {
map = {"user_id": userid};
} else {
map = {"session_id": session_id};
}
print(map);
var response = await Dio().post(
DefaultApi.appUrl + PostAPI.Home,
data: map,
);

  var finalist = await response.data;
  print(response);

  homedata = homescreenmodel.fromJson(finalist);
  print(homedata!.appdata!.maintenanceMode);
  if (homedata!.appdata!.maintenanceMode.toString() == "1") {
    dialogbox.showDialog(
      description: LocaleKeys
          .Sorry_for_the_inconvenience_but_we_are_performing_some_maintenanceatthemomentWewillbebackonlineshortly
          .tr,
    );
  }

  prefs.setString(UD_user_id, homedata!.getprofile!.id.toString());
  prefs.setString(UD_user_name, homedata!.getprofile!.name.toString());
  if (session_id == "") {
    prefs.setString(UD_user_session_id, homedata!.session_id.toString());
  }
  prefs.setString(UD_user_mobile, homedata!.getprofile!.mobile.toString());
  prefs.setString(UD_user_email, homedata!.getprofile!.email.toString());
  prefs.setString(
      UD_user_logintype, homedata!.getprofile!.loginType.toString());
  prefs.setString(UD_user_wallet, homedata!.getprofile!.wallet.toString());
  prefs.setString(UD_user_isnotification,
      homedata!.getprofile!.isNotification.toString());
  prefs.setString(UD_user_ismail, homedata!.getprofile!.isMail.toString());
  prefs.setString(
      UD_user_refer_code, homedata!.getprofile!.referralCode.toString());
  prefs.setString(
      UD_user_profileimage, homedata!.getprofile!.profileImage.toString());
  prefs.setString(APPcurrency, homedata!.appdata!.currency.toString());
  prefs.setString(
      APPcurrency_position, homedata!.appdata!.currencyPosition.toString());
  prefs.setString(APPcart_count, homedata!.cartdata!.totalCount.toString());
  prefs.setString(
      min_order_amount, homedata!.appdata!.minOrderAmount.toString());
  prefs.setString(
      max_order_amount, homedata!.appdata!.maxOrderAmount.toString());
  prefs.setString(restaurantlat, homedata!.appdata!.lat.toString());
  prefs.setString(restaurantlang, homedata!.appdata!.lang.toString());
  prefs.setString(
      deliverycharges, homedata!.appdata!.deliveryCharge.toString());
  prefs.setString(about_us, homedata!.appdata!.aboutContent.toString());
  prefs.setString(
      referral_amount, homedata!.appdata!.referralAmount.toString());
  prefs.setString(
      UD_user_logintype, homedata!.getprofile!.loginType.toString());
  prefs.setString(APPCheck_addons, homedata!.checkaddons.toString());
  prefs.setString(Androidlink, homedata!.appdata!.android.toString());
  prefs.setString(Ioslink, homedata!.appdata!.ios.toString());
  currency = (prefs.getString(APPcurrency) ?? "");
  currency_position = (prefs.getString(APPcurrency_position) ?? "");
  count.cartcountnumber(int.parse(prefs.getString(APPcart_count)!));
  return homedata;
} catch (e) {
  print(e);
  loader.hideLoading();
  loader.showErroDialog(description: "Somthing went wrong!");
}

} error I/flutter (14037): DioError [DioErrorType.response]: Http status error [500]
I/flutter (14037): Source stack:
I/flutter (14037): #0 DioMixin.fetch (package:dio/src/dio_mixin.dart:488:35)
I/flutter (14037): #1 DioMixin.request (package:dio/src/dio_mixin.dart:483:12)
I/flutter (14037): #2 DioMixin.post (package:dio/src/dio_mixin.dart:97:12)
I/flutter (14037): #3 _HomescreenState.homescreenAPI (package:singlerestaurant/pages/Home/homescreen.dart:78:34)
I/flutter (14037):
I/flutter (14037): #4 _FutureBuilderState._subscribe. (package:flutter/src/widgets/async.dart:624:31)
I/flutter (14037): please someone have solved this problem

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

No branches or pull requests