graphicbeacon / photo_gallery_app

A Photo Gallery application built with AngularDart and Aqueduct
5 stars 3 forks source link

EXCEPTION: DioError [DioErrorType.RESPONSE] #1

Closed ghost closed 4 years ago

ghost commented 4 years ago

I am on part 6 btw

EXCEPTION: DioError [DioErrorType.RESPONSE]: XMLHttpRequest error.
STACKTRACE: 
dart:sdk_internal                                    get current
package:dio/src/adapters/browser_adapter.dart 79:20  <fn>
package:stack_trace                                  <fn>
package:angular/src/core/zone/ng_zone.dart 144:18    <fn>
dart:sdk_internal                                    runUnary
package:angular/src/core/zone/ng_zone.dart 141:18    [_runUnary]
package:stack_trace                                  <fn>
package:angular/src/core/zone/ng_zone.dart 144:18    <fn>
dart:sdk_internal                                    runUnary
package:angular/src/core/zone/ng_zone.dart 141:18    [_runUnary]

package:dio/src/adapters/browser_adapter.dart 73:16  <fn>
package:stack_trace                                  <fn>
package:angular/src/core/zone/ng_zone.dart 144:18    <fn>
dart:sdk_internal                                    runUnary
package:angular/src/core/zone/ng_zone.dart 141:18    [_runUnary]
package:stack_trace                                  <fn>
package:angular/src/core/zone/ng_zone.dart 144:18    <fn>
dart:sdk_internal                                    runUnary
package:angular/src/core/zone/ng_zone.dart 141:18    [_runUnary]

dart:sdk_internal                                   then
package:dio/src/adapters/browser_adapter.dart 70:8  fetch
package:dio/src/dio.dart 922:46                     _dispatchRequest
package:stack_trace                                 <fn>
package:angular/src/core/zone/ng_zone.dart 144:18   <fn>
dart:sdk_internal                                   runUnary
package:angular/src/core/zone/ng_zone.dart 141:18   [_runUnary]
dart:sdk_internal                                   <fn>
package:angular/src/core/zone/ng_zone.dart 117:11   <fn>
package:stack_trace                                 <fn>
package:angular/src/core/zone/ng_zone.dart 132:18   <fn>
dart:sdk_internal                                   run
package:angular/src/core/zone/ng_zone.dart 129:18   [_run]

dart:sdk_internal                                  _async
package:dio/src/dio.dart 917:42                    [_dispatchRequest]
dart:sdk_internal                                  dcall
package:dio/src/dio.dart 849:37                    <fn>
package:dio/src/dio.dart 1121:22                   checkIfNeedEnqueue
package:dio/src/dio.dart 846:22                    <fn>
package:stack_trace                                <fn>
package:angular/src/core/zone/ng_zone.dart 132:18  <fn>
dart:sdk_internal                                  run
package:angular/src/core/zone/ng_zone.dart 129:18  [_run]
dart:sdk_internal                                  <fn>
package:angular/src/core/zone/ng_zone.dart 205:11  <fn>
package:stack_trace                                <fn>
package:angular/src/core/zone/ng_zone.dart 132:18  <fn>
dart:sdk_internal                                  run
package:angular/src/core/zone/ng_zone.dart 129:18  [_run]

dart:sdk_internal                                  new
package:dio/src/dio.dart 845:13                    <fn>
dart:sdk_internal                                  _async
package:dio/src/dio.dart 838:15                    <fn>
package:stack_trace                                <fn>
package:angular/src/core/zone/ng_zone.dart 144:18  <fn>
dart:sdk_internal                                  runUnary
package:angular/src/core/zone/ng_zone.dart 141:18  [_runUnary]
dart:sdk_internal                                  <fn>
package:angular/src/core/zone/ng_zone.dart 117:11  <fn>
package:stack_trace                                <fn>
package:angular/src/core/zone/ng_zone.dart 132:18  <fn>
dart:sdk_internal                                  run
package:angular/src/core/zone/ng_zone.dart 129:18  [_run]

dart:sdk_internal                                            then
package:dio/src/dio.dart 893:20                              _request
dart:sdk_internal                                            _async
package:dio/src/dio.dart 799:34                              [_request]
package:dio/src/dio.dart 764:12                              request
dart:sdk_internal                                            _async
package:dio/src/dio.dart 755:33                              request
package:dio/src/dio.dart 404:12                              post
package:pg_client/src/service/gallery_service.dart 27:34     updateGallery
dart:sdk_internal                                            _async
package:pg_client/src/service/gallery_service.dart 26:32     updateGallery
package:pg_client/src/pages/galley_new_component.dart 27:27  updateGallery
dart:sdk_internal                                            _async
package:pg_client/src/pages/galley_new_component.dart 26:21  updateGallery
package:angular/src/core/linker/app_view.dart 598:36         <fn>
package:angular/src/core/zone/ng_zone.dart 132:18            <fn>
dart:sdk_internal                                            run
package:angular/src/core/zone/ng_zone.dart 129:18            [_run]
dart:sdk_internal    
error @ dart_sdk.js:104354
handle @ exceptions.dart:14
call @ exceptions.dart:11
handleUncaughtException @ application_ref.dart:135
(anonymous) @ application_ref.dart:47
(anonymous) @ stack_zone_specification.dart:126
[_run] @ stack_zone_specification.dart:206
(anonymous) @ stack_zone_specification.dart:126
(anonymous) @ ng_zone.dart:144
_rootRunUnary @ dart_sdk.js:34510
runUnary @ dart_sdk.js:33311
[_runUnary] @ ng_zone.dart:141
runUnary @ dart_sdk.js:33673
runUnaryGuarded @ dart_sdk.js:33579
[_sendData] @ dart_sdk.js:27585
[_add] @ dart_sdk.js:27531
[_sendData] @ dart_sdk.js:28253
add @ dart_sdk.js:28047
[_onErrorWithLongStackTrace] @ ng_zone.dart:182
_rootRunBinary @ dart_sdk.js:34524
runBinary @ dart_sdk.js:34056
[_handleUncaughtError] @ stack_zone_specification.dart:160
handleUncaughtError @ dart_sdk.js:33651
_propagateToListeners @ dart_sdk.js:29519
[_completeError] @ dart_sdk.js:29470
[_completeError] @ dart_sdk.js:28966
completeError @ dart_sdk.js:28889
onError @ dart_sdk.js:28734
(anonymous) @ stack_zone_specification.dart:138
[_run] @ stack_zone_specification.dart:206
(anonymous) @ stack_zone_specification.dart:138
(anonymous) @ ng_zone.dart:156
_rootRunBinary @ dart_sdk.js:34518
runBinary @ dart_sdk.js:33319
[_runBinary] @ ng_zone.dart:153
runBinary @ dart_sdk.js:33680
handleError @ dart_sdk.js:29046
handleError @ dart_sdk.js:29597
_propagateToListeners @ dart_sdk.js:29623
[_completeError] @ dart_sdk.js:29470
(anonymous) @ dart_sdk.js:29508
(anonymous) @ ng_zone.dart:117
[_run] @ stack_zone_specification.dart:206
(anonymous) @ stack_zone_specification.dart:116
(anonymous) @ ng_zone.dart:132
_rootRun @ dart_sdk.js:34496
run @ dart_sdk.js:33303
[_run] @ ng_zone.dart:129
run @ dart_sdk.js:33666
runGuarded @ dart_sdk.js:33566
(anonymous) @ dart_sdk.js:33620
_microtaskLoop @ dart_sdk.js:34311
_startMicrotaskLoop @ dart_sdk.js:34317
(anonymous) @ dart_sdk.js:29836
Promise.then (async)
_scheduleImmediateWithPromise @ dart_sdk.js:29834
_scheduleImmediate @ dart_sdk.js:29841
_scheduleAsyncCallback @ dart_sdk.js:34333
_rootScheduleMicrotask @ dart_sdk.js:34568
scheduleMicrotask @ dart_sdk.js:33361
[_scheduleMicrotask] @ ng_zone.dart:125
scheduleMicrotask @ dart_sdk.js:33718
[_asyncCompleteError] @ dart_sdk.js:29507
[_completeError] @ dart_sdk.js:28933
completeError @ dart_sdk.js:28889
(anonymous) @ browser_adapter.dart:73
(anonymous) @ stack_zone_specification.dart:126
[_run] @ stack_zone_specification.dart:206
(anonymous) @ stack_zone_specification.dart:126
(anonymous) @ ng_zone.dart:144
_rootRunUnary @ dart_sdk.js:34504
runUnary @ dart_sdk.js:33311
[_runUnary] @ ng_zone.dart:141
runUnary @ dart_sdk.js:33673
handleValue @ dart_sdk.js:29034
handleValueCallback @ dart_sdk.js:29581
_propagateToListeners @ dart_sdk.js:29619
[_complete] @ dart_sdk.js:29453
_cancelAndValue @ dart_sdk.js:34460
(anonymous) @ dart_sdk.js:15396
_checkAndCall @ dart_sdk.js:4238
dcall @ dart_sdk.js:4243
(anonymous) @ dart_sdk.js:101605
(anonymous) @ stack_zone_specification.dart:126
[_run] @ stack_zone_specification.dart:206
(anonymous) @ stack_zone_specification.dart:126
(anonymous) @ ng_zone.dart:144
_rootRunUnary @ dart_sdk.js:34510
runUnary @ dart_sdk.js:33311
[_runUnary] @ ng_zone.dart:141
runUnary @ dart_sdk.js:33673
runUnaryGuarded @ dart_sdk.js:33579
(anonymous) @ dart_sdk.js:33625
error (async)
[_addEventListener] @ dart_sdk.js:59257
[dartx.addEventListener] @ dart_sdk.js:59247
[_tryResume] @ dart_sdk.js:101631
onData @ dart_sdk.js:101607
get first @ dart_sdk.js:15395
fetch @ browser_adapter.dart:70
_dispatchRequest @ dio.dart:922
(anonymous) @ dart_sdk.js:34196
(anonymous) @ stack_zone_specification.dart:126
[_run] @ stack_zone_specification.dart:206
(anonymous) @ stack_zone_specification.dart:126
(anonymous) @ ng_zone.dart:144
_rootRunUnary @ dart_sdk.js:34504
runUnary @ dart_sdk.js:33311
[_runUnary] @ ng_zone.dart:141
runUnary @ dart_sdk.js:33673
handleValue @ dart_sdk.js:29034
handleValueCallback @ dart_sdk.js:29581
_propagateToListeners @ dart_sdk.js:29619
[_completeWithValue] @ dart_sdk.js:29462
(anonymous) @ dart_sdk.js:29484
(anonymous) @ ng_zone.dart:117
[_run] @ stack_zone_specification.dart:206
(anonymous) @ stack_zone_specification.dart:116
(anonymous) @ ng_zone.dart:132
_rootRun @ dart_sdk.js:34496
run @ dart_sdk.js:33303
[_run] @ ng_zone.dart:129
run @ dart_sdk.js:33666
runGuarded @ dart_sdk.js:33566
(anonymous) @ dart_sdk.js:33620
_microtaskLoop @ dart_sdk.js:34311
_startMicrotaskLoop @ dart_sdk.js:34317
(anonymous) @ dart_sdk.js:29836
Promise.then (async)
_scheduleImmediateWithPromise @ dart_sdk.js:29834
_scheduleImmediate @ dart_sdk.js:29841
_scheduleAsyncCallback @ dart_sdk.js:34333
_rootScheduleMicrotask @ dart_sdk.js:34568
scheduleMicrotask @ dart_sdk.js:33361
[_scheduleMicrotask] @ ng_zone.dart:125
scheduleMicrotask @ dart_sdk.js:33718
[_asyncCompleteWithValue] @ dart_sdk.js:29483
[_asyncComplete] @ dart_sdk.js:29479
runBody @ dart_sdk.js:34228
_async @ dart_sdk.js:34247
transformRequest @ transformer.dart:58
_transformData @ dio.dart:1014
runBody @ dart_sdk.js:34216
_async @ dart_sdk.js:34247
[_transformData] @ dio.dart:986
_dispatchRequest @ dio.dart:921
runBody @ dart_sdk.js:34216
_async @ dart_sdk.js:34247
[_dispatchRequest] @ dio.dart:917
_checkAndCall @ dart_sdk.js:4238
dcall @ dart_sdk.js:4243
(anonymous) @ dio.dart:849
checkIfNeedEnqueue @ dio.dart:1121
(anonymous) @ dio.dart:846
(anonymous) @ dart_sdk.js:28527
[_run] @ stack_zone_specification.dart:206
(anonymous) @ stack_zone_specification.dart:116
(anonymous) @ ng_zone.dart:132
_rootRun @ dart_sdk.js:34490
run @ dart_sdk.js:33303
[_run] @ ng_zone.dart:129
run @ dart_sdk.js:33666
runGuarded @ dart_sdk.js:33566
(anonymous) @ dart_sdk.js:33620
(anonymous) @ ng_zone.dart:205
[_run] @ stack_zone_specification.dart:206
(anonymous) @ stack_zone_specification.dart:116
(anonymous) @ ng_zone.dart:132
_rootRun @ dart_sdk.js:34496
run @ dart_sdk.js:33303
[_run] @ ng_zone.dart:129
run @ dart_sdk.js:33666
(anonymous) @ dart_sdk.js:33605
internalCallback @ dart_sdk.js:20371
setTimeout (async)
_isolate_helper.TimerImpl.new @ dart_sdk.js:20376
_createTimer @ dart_sdk.js:32781
_rootCreateTimer @ dart_sdk.js:34579
createTimer @ dart_sdk.js:33370
[_createTimer] @ ng_zone.dart:210
createTimer @ dart_sdk.js:33726
new @ dart_sdk.js:32761
run @ dart_sdk.js:32774
new @ dart_sdk.js:28525
(anonymous) @ dio.dart:845
runBody @ dart_sdk.js:34216
_async @ dart_sdk.js:34247
(anonymous) @ dio.dart:838
(anonymous) @ stack_zone_specification.dart:126
[_run] @ stack_zone_specification.dart:206
(anonymous) @ stack_zone_specification.dart:126
(anonymous) @ ng_zone.dart:144
_rootRunUnary @ dart_sdk.js:34504
runUnary @ dart_sdk.js:33311
[_runUnary] @ ng_zone.dart:141
runUnary @ dart_sdk.js:33673
handleValue @ dart_sdk.js:29034
handleValueCallback @ dart_sdk.js:29581
_propagateToListeners @ dart_sdk.js:29619
[_completeWithValue] @ dart_sdk.js:29462
(anonymous) @ dart_sdk.js:29484
(anonymous) @ ng_zone.dart:117
[_run] @ stack_zone_specification.dart:206
(anonymous) @ stack_zone_specification.dart:116
(anonymous) @ ng_zone.dart:132
_rootRun @ dart_sdk.js:34496
run @ dart_sdk.js:33303
[_run] @ ng_zone.dart:129
run @ dart_sdk.js:33666
runGuarded @ dart_sdk.js:33566
(anonymous) @ dart_sdk.js:33620
_microtaskLoop @ dart_sdk.js:34311
_startMicrotaskLoop @ dart_sdk.js:34317
(anonymous) @ dart_sdk.js:29836
Promise.then (async)
_scheduleImmediateWithPromise @ dart_sdk.js:29834
_scheduleImmediate @ dart_sdk.js:29841
_scheduleAsyncCallback @ dart_sdk.js:34333
_rootScheduleMicrotask @ dart_sdk.js:34568
scheduleMicrotask @ dart_sdk.js:33361
[_scheduleMicrotask] @ ng_zone.dart:125
scheduleMicrotask @ dart_sdk.js:33718
scheduleMicrotask @ dart_sdk.js:34374
schedule @ dart_sdk.js:30816
[_addPending] @ dart_sdk.js:27575
[_sendData] @ dart_sdk.js:30521
[_add] @ dart_sdk.js:30295
add @ dart_sdk.js:30260
updateGallery @ gallery_form_component.dart:42
[_handle_ngSubmit_3_0] @ gallery_form_component.template.dart:387
(anonymous) @ app_view.dart:598
(anonymous) @ ng_zone.dart:132
_rootRun @ dart_sdk.js:34490
run @ dart_sdk.js:33303
[_run] @ ng_zone.dart:129
run @ dart_sdk.js:33666
runGuarded @ dart_sdk.js:33566
runGuarded @ ng_zone.dart:300
(anonymous) @ app_view.dart:598
(anonymous) @ stack_zone_specification.dart:126
[_run] @ stack_zone_specification.dart:206
(anonymous) @ stack_zone_specification.dart:126
(anonymous) @ ng_zone.dart:144
_rootRunUnary @ dart_sdk.js:34504
runUnary @ dart_sdk.js:33311
[_runUnary] @ ng_zone.dart:141
runUnary @ dart_sdk.js:33673
runUnaryGuarded @ dart_sdk.js:33579
[_sendData] @ dart_sdk.js:27585
[_add] @ dart_sdk.js:27531
[_sendData] @ dart_sdk.js:28253
add @ dart_sdk.js:28047
onSubmit @ abstract_form.dart:34
(anonymous) @ app_view.dart:598
(anonymous) @ ng_zone.dart:132
_rootRun @ dart_sdk.js:34496
run @ dart_sdk.js:33303
[_run] @ ng_zone.dart:129
run @ dart_sdk.js:33666
runGuarded @ dart_sdk.js:33566
runGuarded @ ng_zone.dart:300
(anonymous) @ app_view.dart:598
Show 227 more frames
localhost:8888/gallery:1 Failed to load resource: net::ERR_CONNECTION_CLOSED

Code for gallery_service.dart


import 'package:angular/angular.dart';
import 'package:dio/dio.dart';

import '../models/gallery.dart';

@Injectable()
class GalleryService {
  final Dio _dio = Dio(
    BaseOptions(
      baseUrl: "https://localhost:8888/gallery",
    ),
  );

  Future<List<Gallery>> getGalleries() async {
    final response = await _dio.get("http://localhost:8888/gallery");

    final responseGalleries = ((response.data) as List).map(
      (e) => Gallery.fromJson(e),
    );

    return responseGalleries.toList();
  }

  Future<Gallery> updateGallery(Gallery payload) async {
    final responsee = await _dio.post('', data: payload.toJson());
    return Gallery.fromJson(responsee.data);
  }
}

Code for gallery controller.dart


import 'package:aqueduct/aqueduct.dart';
import 'package:pg_server/src/models/gallery.dart';

class GalleryController extends ResourceController {
  GalleryController(this.context);

  final ManagedContext context;

  @Operation.get()
  Future<Response> getGalleries() async {
    final query = Query<Gallery>(context);
    return Response.ok(await query.fetch());
  }

  @Operation.post()
  Future<Response> createGallery(@Bind.body() Gallery payload) async {
    final query = Query<Gallery>(context)..values = payload;
    return Response.ok(await query.insert());
  }
}

Code for the gallery.dart for pg_server:

import 'package:aqueduct/aqueduct.dart';

class Gallery extends ManagedObject<_Gallery> implements _Gallery {}

class _Gallery {
  @primaryKey
  int id;

  String title;
  DateTime publishDate;

  @Column(nullable: true)
  String description;
}

Code for gallery.dart for pg_client:

import 'dart:html';

class Gallery {
  String title;
  String publishDate;
  String description;
  String thumbnailUrl;

  Gallery([
    this.title,
    this.publishDate,
    this.description,
    this.thumbnailUrl,
  ]);
  Gallery.fromJson(Map json) {
    title = json['title'];
    publishDate = json['publishDate'];
    description = json['description'];
    thumbnailUrl = json['thumbnailUrl'];
  }

  Map<String, dynamic> toJson() {
    return {
      'title': title,
      'publishDate': publishDate,
      'description': description,
    };
  }
}
graphicbeacon commented 4 years ago

I see these lines in the stack trace:

package:pg_client/src/pages/galley_new_component.dart 27:27
..
package:pg_client/src/pages/galley_new_component.dart 26:21

What do you have in gallery_new_component.dart? Also what do you see in the Network panel?

ghost commented 4 years ago

gallery_new_component.dart:

import 'package:angular/angular.dart';
import 'package:angular_router/angular_router.dart';
import 'package:pg_client/src/common/gallery_from/gallery_form_component.dart';
import 'package:pg_client/src/models/gallery.dart';
import 'package:pg_client/src/service/gallery_service.dart';

@Component(
    selector: 'gallery-new',
    template: '''
    <div class="row">
      <div class="col s12">
        <h3>Add new Gallery</h3>
      </div>
    </div>
 <gallery-form (onUpdate)="updateGallery"></gallery-form>
  ''',
  directives: [GalleryFormComponent],
  providers: [ClassProvider(GalleryService)]
)
class GalleryNewComponent {
  GalleryNewComponent(this._galleryService, this._router);

  final GalleryService _galleryService;
  final Router _router;

  void updateGallery(Gallery gallery) async {
    await _galleryService.updateGallery(gallery);
    await _router.navigate('/');
  }
}
graphicbeacon commented 4 years ago

What do you see in the Network Panel?

ghost commented 4 years ago

I have found the error:

Sorry I have wasted your time, it was a silly mistake, I put an https in the base url in gallery_service.dart instead of http