Does anyone know how to fix this?
I tried to use these codes for issuing access token, but i got errored.
protected function oauthLogin(Request $request)
{
$client = DB::table('oauth_clients')
->where('password_client', true)
->first();
$request->request->add([
"grant_type" => "password",
"username" => $request->email,
"password" => $request->password,
"client_id" => $client->id,
"client_secret" => $client->secret,
]);
$tokenRequest = $request->create(
env('APP_URL') . 'api/v1/oauth/token',
'post'
);
$instance = Route::dispatch($tokenRequest);
return json_decode($instance->getContent());
}
This was the error traceable logs. I dont know if this is related because my even my credentials was correct so, i dont think, that my credentials was denied. I tried it also to oauth/token and it was working. Still the same error. I've got.
[2019-02-20 13:22:09] local.ERROR: League\OAuth2\Server\Exception\OAuthServerException: The resource owner or authorization server denied the request. in D:\laragon\www\auth-service-optimize\vendor\league\oauth2-server\src\Exception\OAuthServerException.php:215
Stack trace:
#0 D:\laragon\www\auth-service-optimize\vendor\league\oauth2-server\src\AuthorizationValidators\BearerTokenValidator.php(73): League\OAuth2\Server\Exception\OAuthServerException::accessDenied('Access token co...')
#1 D:\laragon\www\auth-service-optimize\vendor\league\oauth2-server\src\ResourceServer.php(84): League\OAuth2\Server\AuthorizationValidators\BearerTokenValidator->validateAuthorization(Object(Zend\Diactoros\ServerRequest))
#2 D:\laragon\www\auth-service-optimize\vendor\laravel\passport\src\Guards\TokenGuard.php(174): League\OAuth2\Server\ResourceServer->validateAuthenticatedRequest(Object(Zend\Diactoros\ServerRequest))
#3 D:\laragon\www\auth-service-optimize\vendor\laravel\passport\src\Guards\TokenGuard.php(126): Laravel\Passport\Guards\TokenGuard->getPsrRequestViaBearerToken(Object(Laravel\Lumen\Http\Request))
#4 D:\laragon\www\auth-service-optimize\vendor\laravel\passport\src\Guards\TokenGuard.php(89): Laravel\Passport\Guards\TokenGuard->authenticateViaBearerToken(Object(Laravel\Lumen\Http\Request))
#5 D:\laragon\www\auth-service-optimize\vendor\laravel\passport\src\PassportServiceProvider.php(274): Laravel\Passport\Guards\TokenGuard->user(Object(Laravel\Lumen\Http\Request))
#6 [internal function]: Laravel\Passport\PassportServiceProvider->Laravel\Passport\{closure}(Object(Laravel\Lumen\Http\Request), NULL)
#7 D:\laragon\www\auth-service-optimize\vendor\illuminate\auth\RequestGuard.php(58): call_user_func(Object(Closure), Object(Laravel\Lumen\Http\Request), NULL)
#8 D:\laragon\www\auth-service-optimize\app\Http\Controllers\AuthController.php(169): Illuminate\Auth\RequestGuard->user()
#9 [internal function]: App\Http\Controllers\AuthController->adminLogin(Object(Laravel\Lumen\Http\Request))
#10 D:\laragon\www\auth-service-optimize\vendor\illuminate\container\BoundMethod.php(29): call_user_func_array(Array, Array)
#11 D:\laragon\www\auth-service-optimize\vendor\illuminate\container\BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#12 D:\laragon\www\auth-service-optimize\vendor\illuminate\container\BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Laravel\Lumen\Application), Array, Object(Closure))
#13 D:\laragon\www\auth-service-optimize\vendor\illuminate\container\Container.php(572): Illuminate\Container\BoundMethod::call(Object(Laravel\Lumen\Application), Array, Array, NULL)
#14 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(378): Illuminate\Container\Container->call(Array, Array)
#15 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(344): Laravel\Lumen\Application->callControllerCallable(Array, Array)
#16 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(318): Laravel\Lumen\Application->callLumenController(Object(App\Http\Controllers\AuthController), 'adminLogin', Array)
#17 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(280): Laravel\Lumen\Application->callControllerAction(Array)
#18 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(265): Laravel\Lumen\Application->callActionOnArrayBasedRoute(Array)
#19 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(165): Laravel\Lumen\Application->handleFoundRoute(Array)
#20 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(418): Laravel\Lumen\Application->Laravel\Lumen\Concerns\{closure}(Object(Laravel\Lumen\Http\Request))
#21 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(171): Laravel\Lumen\Application->sendThroughPipeline(Array, Object(Closure))
#22 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(108): Laravel\Lumen\Application->dispatch(NULL)
#23 D:\laragon\www\auth-service-optimize\public\index.php(28): Laravel\Lumen\Application->run()
#24 {main} {"exception":"[object] (League\\OAuth2\\Server\\Exception\\OAuthServerException(code: 9): The resource owner or authorization server denied the request. at D:\\laragon\\www\\auth-service-optimize\\vendor\\league\\oauth2-server\\src\\Exception\\OAuthServerException.php:215)
[stacktrace]
#0 D:\\laragon\\www\\auth-service-optimize\\vendor\\league\\oauth2-server\\src\\AuthorizationValidators\\BearerTokenValidator.php(73): League\\OAuth2\\Server\\Exception\\OAuthServerException::accessDenied('Access token co...')
#1 D:\\laragon\\www\\auth-service-optimize\\vendor\\league\\oauth2-server\\src\\ResourceServer.php(84): League\\OAuth2\\Server\\AuthorizationValidators\\BearerTokenValidator->validateAuthorization(Object(Zend\\Diactoros\\ServerRequest))
#2 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\passport\\src\\Guards\\TokenGuard.php(174): League\\OAuth2\\Server\\ResourceServer->validateAuthenticatedRequest(Object(Zend\\Diactoros\\ServerRequest))
#3 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\passport\\src\\Guards\\TokenGuard.php(126): Laravel\\Passport\\Guards\\TokenGuard->getPsrRequestViaBearerToken(Object(Laravel\\Lumen\\Http\\Request))
#4 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\passport\\src\\Guards\\TokenGuard.php(89): Laravel\\Passport\\Guards\\TokenGuard->authenticateViaBearerToken(Object(Laravel\\Lumen\\Http\\Request))
#5 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\passport\\src\\PassportServiceProvider.php(274): Laravel\\Passport\\Guards\\TokenGuard->user(Object(Laravel\\Lumen\\Http\\Request))
#6 [internal function]: Laravel\\Passport\\PassportServiceProvider->Laravel\\Passport\\{closure}(Object(Laravel\\Lumen\\Http\\Request), NULL)
#7 D:\\laragon\\www\\auth-service-optimize\\vendor\\illuminate\\auth\\RequestGuard.php(58): call_user_func(Object(Closure), Object(Laravel\\Lumen\\Http\\Request), NULL)
#8 D:\\laragon\\www\\auth-service-optimize\\app\\Http\\Controllers\\AuthController.php(169): Illuminate\\Auth\\RequestGuard->user()
#9 [internal function]: App\\Http\\Controllers\\AuthController->adminLogin(Object(Laravel\\Lumen\\Http\\Request))
#10 D:\\laragon\\www\\auth-service-optimize\\vendor\\illuminate\\container\\BoundMethod.php(29): call_user_func_array(Array, Array)
#11 D:\\laragon\\www\\auth-service-optimize\\vendor\\illuminate\\container\\BoundMethod.php(87): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#12 D:\\laragon\\www\\auth-service-optimize\\vendor\\illuminate\\container\\BoundMethod.php(31): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Laravel\\Lumen\\Application), Array, Object(Closure))
#13 D:\\laragon\\www\\auth-service-optimize\\vendor\\illuminate\\container\\Container.php(572): Illuminate\\Container\\BoundMethod::call(Object(Laravel\\Lumen\\Application), Array, Array, NULL)
#14 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(378): Illuminate\\Container\\Container->call(Array, Array)
#15 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(344): Laravel\\Lumen\\Application->callControllerCallable(Array, Array)
#16 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(318): Laravel\\Lumen\\Application->callLumenController(Object(App\\Http\\Controllers\\AuthController), 'adminLogin', Array)
#17 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(280): Laravel\\Lumen\\Application->callControllerAction(Array)
#18 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(265): Laravel\\Lumen\\Application->callActionOnArrayBasedRoute(Array)
#19 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(165): Laravel\\Lumen\\Application->handleFoundRoute(Array)
#20 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(418): Laravel\\Lumen\\Application->Laravel\\Lumen\\Concerns\\{closure}(Object(Laravel\\Lumen\\Http\\Request))
#21 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(171): Laravel\\Lumen\\Application->sendThroughPipeline(Array, Object(Closure))
#22 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(108): Laravel\\Lumen\\Application->dispatch(NULL)
#23 D:\\laragon\\www\\auth-service-optimize\\public\\index.php(28): Laravel\\Lumen\\Application->run()
#24 {main}
"}
[2019-02-20 13:22:09] local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Call to undefined method Laravel\Lumen\Routing\Router::dispatch() in D:\laragon\www\auth-service-optimize\vendor\illuminate\support\Facades\Facade.php:237
Stack trace:
#0 D:\laragon\www\auth-service-optimize\app\Http\Controllers\AuthController.php(202): Illuminate\Support\Facades\Facade::__callStatic('dispatch', Array)
#1 D:\laragon\www\auth-service-optimize\app\Http\Controllers\AuthController.php(171): App\Http\Controllers\AuthController->oauthLogin(Object(Laravel\Lumen\Http\Request))
#2 [internal function]: App\Http\Controllers\AuthController->adminLogin(Object(Laravel\Lumen\Http\Request))
#3 D:\laragon\www\auth-service-optimize\vendor\illuminate\container\BoundMethod.php(29): call_user_func_array(Array, Array)
#4 D:\laragon\www\auth-service-optimize\vendor\illuminate\container\BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#5 D:\laragon\www\auth-service-optimize\vendor\illuminate\container\BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Laravel\Lumen\Application), Array, Object(Closure))
#6 D:\laragon\www\auth-service-optimize\vendor\illuminate\container\Container.php(572): Illuminate\Container\BoundMethod::call(Object(Laravel\Lumen\Application), Array, Array, NULL)
#7 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(378): Illuminate\Container\Container->call(Array, Array)
#8 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(344): Laravel\Lumen\Application->callControllerCallable(Array, Array)
#9 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(318): Laravel\Lumen\Application->callLumenController(Object(App\Http\Controllers\AuthController), 'adminLogin', Array)
#10 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(280): Laravel\Lumen\Application->callControllerAction(Array)
#11 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(265): Laravel\Lumen\Application->callActionOnArrayBasedRoute(Array)
#12 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(165): Laravel\Lumen\Application->handleFoundRoute(Array)
#13 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(418): Laravel\Lumen\Application->Laravel\Lumen\Concerns\{closure}(Object(Laravel\Lumen\Http\Request))
#14 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(171): Laravel\Lumen\Application->sendThroughPipeline(Array, Object(Closure))
#15 D:\laragon\www\auth-service-optimize\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(108): Laravel\Lumen\Application->dispatch(NULL)
#16 D:\laragon\www\auth-service-optimize\public\index.php(28): Laravel\Lumen\Application->run()
#17 {main} {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Call to undefined method Laravel\\Lumen\\Routing\\Router::dispatch() at D:\\laragon\\www\\auth-service-optimize\\vendor\\illuminate\\support\\Facades\\Facade.php:237)
[stacktrace]
#0 D:\\laragon\\www\\auth-service-optimize\\app\\Http\\Controllers\\AuthController.php(202): Illuminate\\Support\\Facades\\Facade::__callStatic('dispatch', Array)
#1 D:\\laragon\\www\\auth-service-optimize\\app\\Http\\Controllers\\AuthController.php(171): App\\Http\\Controllers\\AuthController->oauthLogin(Object(Laravel\\Lumen\\Http\\Request))
#2 [internal function]: App\\Http\\Controllers\\AuthController->adminLogin(Object(Laravel\\Lumen\\Http\\Request))
#3 D:\\laragon\\www\\auth-service-optimize\\vendor\\illuminate\\container\\BoundMethod.php(29): call_user_func_array(Array, Array)
#4 D:\\laragon\\www\\auth-service-optimize\\vendor\\illuminate\\container\\BoundMethod.php(87): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#5 D:\\laragon\\www\\auth-service-optimize\\vendor\\illuminate\\container\\BoundMethod.php(31): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Laravel\\Lumen\\Application), Array, Object(Closure))
#6 D:\\laragon\\www\\auth-service-optimize\\vendor\\illuminate\\container\\Container.php(572): Illuminate\\Container\\BoundMethod::call(Object(Laravel\\Lumen\\Application), Array, Array, NULL)
#7 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(378): Illuminate\\Container\\Container->call(Array, Array)
#8 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(344): Laravel\\Lumen\\Application->callControllerCallable(Array, Array)
#9 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(318): Laravel\\Lumen\\Application->callLumenController(Object(App\\Http\\Controllers\\AuthController), 'adminLogin', Array)
#10 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(280): Laravel\\Lumen\\Application->callControllerAction(Array)
#11 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(265): Laravel\\Lumen\\Application->callActionOnArrayBasedRoute(Array)
#12 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(165): Laravel\\Lumen\\Application->handleFoundRoute(Array)
#13 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(418): Laravel\\Lumen\\Application->Laravel\\Lumen\\Concerns\\{closure}(Object(Laravel\\Lumen\\Http\\Request))
#14 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(171): Laravel\\Lumen\\Application->sendThroughPipeline(Array, Object(Closure))
#15 D:\\laragon\\www\\auth-service-optimize\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(108): Laravel\\Lumen\\Application->dispatch(NULL)
#16 D:\\laragon\\www\\auth-service-optimize\\public\\index.php(28): Laravel\\Lumen\\Application->run()
#17 {main}
"}
The request that is dispatched is without the credentials added in the preceding line.
The reason being that Request::create returns a new request instance.
Add the request parameters in the newly created on $request and then dispatch it.
$tokenRequest = $request->create(
env('APP_URL') . 'api/v1/oauth/token',
'POST'
);
$tokenRequest->request->add([
"grant_type" => "password",
"username" => $request->email,
"password" => $request->password,
"client_id" => $client->id,
"client_secret" => $client->secret,
]);
$response = app()->handle($tokenRequest);
Related
I have follow code. I need to handle Exception in it, but I can't do it. And can't understand the reason.
try {
print("aaa");
List<List<dynamic>> result =
await connection.query(sql).timeout(Duration(seconds: 120));
print('bbb');
if (result.isEmpty) {
sql = """ ... """;
await connection.query(sql);
} else {
int dbXmlId = result[0][0];
DateTime dbXMLDocDate = result[0][1];
if (dbXMLDocDate.isBefore(DateTime.parse(docDate!))) {
sql = """ ... """;
// print(sql);
await connection.query(sql);
sql = """ .... """;
currentJob['filesInserted']++;
await connection.query(sql);
} else {
sql = """ .... """;
await connection.query(sql);
}
}
} on PostgreSQLException catch (e) {
print('Exception during Insert in xml_files: $e');
exit(0);
} on SocketException catch (e) {
// пытаемся багу поймать
print('SocketException during Insert in xml_files: $e');
exit(0);
} on Exception catch (e) {
print('BaseException during Insert in xml_files: $e');
exit(0);
} catch (e) {
print("We should not reach this");
}
What I am getting on console:
aaa
Unhandled exception:
SocketException: Write failed (OS Error: An existing connection was forcibly closed by the remote host, errno = 10054), address = localhost, port = 51230
#0 _NativeSocket.write (dart:io-patch/socket_patch.dart:1182:34)
#1 _RawSocket.write (dart:io-patch/socket_patch.dart:1897:15)
#2 _Socket._write (dart:io-patch/socket_patch.dart:2334:18)
#3 _SocketStreamConsumer.write (dart:io-patch/socket_patch.dart:2082:26)
#4 _SocketStreamConsumer.addStream.<anonymous closure> (dart:io-patch/socket_patch.dart:2056:11)
#5 _RootZone.runUnaryGuarded (dart:async/zone.dart:1620:10)
#6 _BufferingStreamSubscription._sendData(dart:async/stream_impl.dart:341:11)
#7 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#8 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:733:19)
#9 _StreamController._add (dart:async/stream_controller.dart:607:7)
#10 _StreamController.add (dart:async/stream_controller.dart:554:5)
#11 _StreamSinkImpl.add (dart:io/io_sink.dart:136:17)
#12 _Socket.add (dart:io-patch/socket_patch.dart:2181:38)
#13 Query.sendExtended (package:postgres/src/query.dart:98:12)
#14 _PostgreSQLConnectionStateIdle.processQuery (package:postgres/src/connection_fsm.dart:214:9)
#15 _PostgreSQLConnectionStateIdle.awake (package:postgres/srcconnection_fsm.dart:200:14)
#16 _PostgreSQLExecutionContextMixin._enqueue (package:postgres/srcconnection.dart:516:67)
#17 _PostgreSQLExecutionContextMixin._query (package:postgres/srcconnection.dart:460:15)
#18 _PostgreSQLExecutionContextMixin.query (package:postgres/srcconnection.dart:427:7)
#19 insertOrUpdateXmlFiles (package:data_loader/Servicesftp_service.dart:499:53)
#20 scanUnpackedFolder (package:data_loader/Services/ftp_service.dart:360:11)
<asynchronous suspension>
#21 unpackArchive (package:data_loader/Services/ftp_service.dart:320:6)
<asynchronous suspension>
#22 downloadArchive (package:data_loader/Services/ftp_service.dart:281:7)
<asynchronous suspension>
#23 runFtpParsingOrOnlyUnpackArchives (package:data_loader/Services/ftp_service.dart:736:5)
<asynchronous suspension>
#24 choiceOfProcessingAction (package:data_loader/Services/ftp_service.dart:658:9)
<asynchronous suspension>
#25 startNewJob (package:data_loader/Services/ftp_service.dart:762:5)
<asynchronous suspension>
#26 main.<anonymous closure> (file:///D:/code/zakupki/data_loader/bin/data_loader.dart:61:9)
<asynchronous suspension>
#27 Alfred._incomingRequest (package:alfred/src/alfred.dart:345:15)
<asynchronous suspension>
#28 _QueuedFuture.execute (package:queue/src/dart_queue_base.dart:26:16)
<asynchronous suspension>
I am seeing on console: aaa but do not see bbb and try-catch do not handle an Exception between them.
Full code: https://gist.github.com/bubnenkoff/7377f735671aacd624371a14151856f4
Solved though chat so this is a resume:
There have been created an issue for this problem here: https://github.com/isoos/postgresql-dart/issues/23
Initial testing shows that it might be because the package are using a synchronously completer, which is really a great way to get a lot of potential issues if you read the official documentation: https://api.dart.dev/stable/2.15.1/dart-async/Completer/Completer.sync.html
If the Completer is changed to a normal asynchronously completer, it is possible to catch the exception from the question.
The issue might be solved in another way but the conclusion is that the problem (with not being able to catch the exceptions, not the exceptions themself) is very likely in the postgres package and should be fixed here.
Am trying to loop in multiple lists and finally comparing their names and delete it from a list if they don't match ...
but am getting this error:
Concurrent modification during iteration:
although i have took a copy of the original list just to avoid this error .. but still am getting it .. what i tried is:
globals.filteredPollsList = pollsList;
pollsList.forEach( (p) {
for (var e in entitiesList) {
print(e.name);
for (var entity in entitiesFilter) {
print(entity);
print(e.name);
if (e.name != entity && p.entityId != e.id) {
print('true');
globals.filteredPollsList.remove(p);
}
}
}
});
but am getting this error:
flutter: ══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
flutter: The following ConcurrentModificationError was thrown while handling a gesture:
flutter: Concurrent modification during iteration: Instance(length:8) of '_GrowableList'.
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #0 List.forEach (dart:core/runtime/libgrowable_array.dart:279:36)
flutter: #1 _ShapedWidgetState.filterPoll (package:moi_polls_app/pages/home.page.dart:1484:15)
flutter: #2 _ShapedWidgetState.build.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:moi_polls_app/pages/home.page.dart:1896:45)
flutter: #3 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:507:14)
flutter: #4 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:562:30)
flutter: #5 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
flutter: #6 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:242:9)
flutter: #7 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:175:7)
flutter: #8 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:315:9)
flutter: #9 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
flutter: #10 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
flutter: #11 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:180:19)
flutter: #12 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:158:22)
flutter: #13 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:138:7)
flutter: #14 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:101:7)
flutter: #15 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:85:7)
flutter: #16 _invoke1 (dart:ui/hooks.dart:168:13)
flutter: #17 _dispatchPointerDataPacket (dart:ui/hooks.dart:122:5)
flutter:
flutter: Handler: onTap
flutter: Recognizer:
flutter: TapGestureRecognizer#e99b3(debugOwner: GestureDetector, state: possible, won arena, finalPosition:
flutter: Offset(283.3, 608.7), sent tap down)
how to solve this?
If you want to copy your list use this:
globals.filteredPollsList = List.from(pollsList);
Below code snippet throws Format Exception in Flutter json decode, Any suggestion please?
import 'dart:async' show Future;
import 'dart:convert';
Future<String> readBooks() async {
String jsonString = '{"description":"As part of the "You Don’t Know JS" series","quantity":55}';
Map<String, dynamic> books = json.decode(jsonString);
return jsonString;
}
Format Exception:
2018-10-23 20:40:30.680 18115-18142/addon.com.bookshop E/flutter:
[ERROR:flutter/shell/common/shell.cc(181)] Dart Error: Unhandled
exception:
FormatException: Unexpected character (at character 26)
{"name":"As part of the "You Don’t Know JS" series","Age":55}
^
#0 _ChunkedJsonParser.fail (dart:convert/runtime/libconvert_patch.dart:1358:5)
#1 _ChunkedJsonParser.parse (dart:convert/runtime/libconvert_patch.dart:919:48)
#2 _parseJson (dart:convert/runtime/libconvert_patch.dart:29:10)
#3 JsonDecoder.convert (dart:convert/json.dart:540:36)
#4 JsonCodec.decode (dart:convert/json.dart:167:41)
#5 _MyHomePageState.readBooks (file:///E:/Me/TimePass/flutter/book_shop/lib/main.dart:58:39)
<asynchronous suspension>
#6 _MyHomePageState.build.<anonymous closure> (file:///E:/Me/TimePass/flutter/book_shop/lib/main.dart:48:39)
<asynchronous suspension>
#7 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:503:14)
#8 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:558:30)
#9 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
#10 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:242:9)
#11 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:175:7)
#12 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:315:9)
#13 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
#14 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
#15 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:143:19)
#16 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:121:22)
#17 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:101:7)
#18 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue
(package:flutter/src/gestures/binding.dart:64:7)
#19 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket
(package:flutter/src/gestures/binding.dart:48:7)
#20 _invoke1 (dart:ui/hooks.dart:142:13)
#21 _dispatchPointerDataPacket (dart:ui/hooks.dart:99:5)
That's just invalid JSON.
The inner quotes need to be escaped as \" to make your JSON valid.
I am using Event Channels in Flutter to return beacon data from Native SDK to Flutter. This was working fine until a recent Flutter upgrade.Now, I am getting the following error.
type '(PlatformException) => void' is not a subtype of type '(Object) => FutureOr<dynamic>
with the following stack trace:
#0 _registerErrorHandler (dart:async/async_error.dart:22:60)
#1 _BufferingStreamSubscription.onError (dart:async/stream_impl.dart:146:16)
#2 new _BufferingStreamSubscription (dart:async/stream_impl.dart:113:10)
#3 new _ControllerSubscription (dart:async/stream_controller.dart)
#4 new _BroadcastSubscription (dart:async/broadcast_stream_controller.dart)
#5 _BroadcastStreamController._subscribe (dart:async/broadcast_stream_controller.dart:212:46)
#6 _ControllerStream._createSubscription (dart:async/stream_controller.dart:817:19)
#7 _StreamImpl.listen (dart:async/stream_impl.dart:466:9)
#8 _MyHomePageState.initPlatformState.<anonymous closure>.<anonymous closure> (file:///Users/chaythanyanair/Documents/Qburst/Learn/flutter_poc/lib/main.dart:95:43)
#9 _RootZone.runUnary (dart:async/zone.dart:1381:54)
#10 _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
#11 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:633:45)
#12 Future._propagateToListeners (dart:async/future_impl.dart:662:32)
#13 Future._complete (dart:async/future_impl.dart:467:7)
#14 _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
#15 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart)
<asynchronous suspension>
#16 _MyHomePageState.initPlatformState.<anonymous closure> (file:///Users/chaythanyanair/Documents/Qburst/Learn/flutter_poc/lib/main.dart:89:24)
<asynchronous suspension>
#17 _RootZone.runUnary (dart:async/zone.dart:1381:54)
#18 _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
#19 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:633:45)
#20 Future._propagateToListeners (dart:async/future_impl.dart:662:32)
#21 Future._complete (dart:async/future_impl.dart:467:7)
#22 _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
#23 User_Profile.getUser (package:flutter_poc/Models/User.dart)
<asynchronous suspension>
#24 _MyHomePageState.initPlatformState (file:///Users/chaythanyanair/Documents/Qburst/Learn/flutter_poc/lib/main.dart:69:24)
<asynchronous suspension>
#25 _MyHomePageState.initState (file:///Users/chaythanyanair/Documents/Qburst/Learn/flutter_poc/lib/main.dart:52:5)
#26 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3734:58)
#27 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3600:5)
#28 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890:14)
#29 Element.updateChild
This is my EventChannel implementation:
static const platform = const MethodChannel('samples.flutter.io/initialiseRanging');
static const stream =
const EventChannel('samples.flutter.io/ranging');
try {
await platform.invokeMethod('initialiseRanging').then((result){
print(result);
setState(() {
_currentValue = result;
});
stream.receiveBroadcastStream().listen(_onEvent, onError: _onError);
});
} on PlatformException catch (e) {
print( "{e.message}");
}
This is how the _onEvent and _onError functions are implemented.
void _onEvent(Object event) {
setState(() {
_currentValue = event.toString();
});
print(event);
}
void _onError(PlatformException error) {
print(error);
}
Any idea on why this could possible happen?
void _onError(PlatformException error) {
should be
void _onError(Object error) {
Even when you are only interested in PlatformException or even when this is the only exception that happened so far, doesn't mean there can't be others. The expected handler function needs to match the parameter type, instead of only the exceptions you expect.
Here is my server side dart code:
import 'dart:io';
import 'package:http_server/http_server.dart';
void main() {
HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 8080).then((server) {
server.listen((HttpRequest request) {
if (request.method.toLowerCase() == 'post' && request.uri.path == '/upload') {
HttpBodyHandler.processRequest(request).then((body) {
HttpBodyFileUpload fileUpload = body.body['file'];
File file = new File('aaa');
file.writeAsBytes(fileUpload.content, mode: FileMode.WRITE).then((_) {
request.response.close();
});
});
}
});
});
}
and my error is:
Unhandled exception:
Uncaught Error: FormatException: Bad UTF-8 encoding 0xbf
Stack Trace:
#0 _Utf8Decoder.convert (dart:convert/utf.dart:534)
#1 _Utf8ConversionSink.addSlice (dart:convert/string_conversion.dart:334)
#2 _Utf8ConversionSink.add (dart:convert/string_conversion.dart:330)
#3 _ConverterStreamEventSink.add (dart:convert/chunked_conversion.dart:89)
#4 _handleData (dart:async/stream_transformers.dart:119)
#5 _RootZone.runUnaryGuarded (dart:async/zone.dart:1020)
#6 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341)
#7 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:270)
#8 _StreamController&&_SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:578)
#9 _StreamController._add (dart:async/stream_controller.dart:453)
#10 _StreamController.add (dart:async/stream_controller.dart:410)
#11 BoundMultipartStream._parse.reportData (package:mime/src/bound_multipart_stream.dart:161:34)
#12 BoundMultipartStream._parse (package:mime/src/bound_multipart_stream.dart:318:28)
#13 BoundMultipartStream.BoundMultipartStream.<anonymous closure>.<anonymous closure> (package:mime/src/bound_multipart_stream.dart:111:24)
#14 _RootZone.runUnaryGuarded (dart:async/zone.dart:1020)
#15 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341)
#16 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:270)
#17 _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:122)
#18 _ForwardingStream._handleData (dart:async/stream_pipe.dart:86)
#19 _handleData (dart:async/stream_pipe.dart:154)
#20 _RootZone.runUnaryGuarded (dart:async/zone.dart:1020)
#21 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341)
#22 _DelayedData.perform (dart:async/stream_impl.dart:595)
#23 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:711)
#24 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:671)
#25 _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:41)
#26 _asyncRunCallback (dart:async/schedule_microtask.dart:48)
#27 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:126)
#0 _rootHandleUncaughtError.<anonymous closure> (dart:async/zone.dart:820)
#1 _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:41)
#2 _asyncRunCallback (dart:async/schedule_microtask.dart:48)
#3 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:126)
Process finished with exit code 255
I used postman to make a post, I chose form-data and add a key called file, value is a txt file.
after send my post to dart server, i got this exception.
is there something wrong with the post ? or the dart code ?
I'm really new to dart, please help me out...
thank you.