Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
a3b17838
Commit
a3b17838
authored
Mar 25, 2016
by
Ian Hickson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2892 from Hixie/fetch-error-cleanup
Clean up prints in services/*
parents
cef24293
da48e2a3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
22 deletions
+42
-22
mojo_client.dart
packages/flutter/lib/src/http/mojo_client.dart
+8
-2
fetch.dart
packages/flutter/lib/src/services/fetch.dart
+27
-12
image_cache.dart
packages/flutter/lib/src/services/image_cache.dart
+7
-8
No files found.
packages/flutter/lib/src/http/mojo_client.dart
View file @
a3b17838
...
...
@@ -149,8 +149,14 @@ class MojoClient {
ByteData
data
=
await
mojo
.
DataPipeDrainer
.
drainHandle
(
response
.
body
);
Uint8List
bodyBytes
=
new
Uint8List
.
view
(
data
.
buffer
);
return
new
Response
(
bodyBytes:
bodyBytes
,
statusCode:
response
.
statusCode
);
}
catch
(
e
)
{
print
(
"NetworkService unavailable
$e
"
);
}
catch
(
exception
)
{
assert
(()
{
debugPrint
(
'-- EXCEPTION CAUGHT BY NETWORKING HTTP LIBRARY -------------------------'
);
debugPrint
(
'An exception was raised while sending bytes to the Mojo network library:'
);
debugPrint
(
'
$exception
'
);
debugPrint
(
'------------------------------------------------------------------------'
);
return
true
;
});
return
new
Response
(
statusCode:
500
);
}
finally
{
loader
.
close
();
...
...
packages/flutter/lib/src/services/fetch.dart
View file @
a3b17838
...
...
@@ -4,32 +4,47 @@
import
'dart:async'
;
import
'package:mojo/mojo/url_request.mojom.dart'
;
import
'package:mojo/mojo/url_response.mojom.dart'
;
import
'package:mojo_services/mojo/url_loader.mojom.dart'
;
import
'package:mojo/mojo/url_request.mojom.dart'
as
mojom
;
import
'package:mojo/mojo/url_response.mojom.dart'
as
mojom
;
import
'package:mojo_services/mojo/url_loader.mojom.dart'
as
mojom
;
import
'../http/mojo_client.dart'
;
import
'print.dart'
;
export
'package:mojo/mojo/url_response.mojom.dart'
show
UrlResponse
;
Future
<
UrlResponse
>
fetch
(
UrlRequest
request
)
async
{
UrlLoaderProxy
loader
=
new
UrlLoaderProxy
.
unbound
();
Future
<
mojom
.
UrlResponse
>
fetch
(
mojom
.
UrlRequest
request
,
{
bool
require200:
false
}
)
async
{
mojom
.
UrlLoaderProxy
loader
=
new
mojom
.
UrlLoaderProxy
.
unbound
();
try
{
MojoClient
.
networkService
.
ptr
.
createUrlLoader
(
loader
);
UrlResponse
response
=
(
await
loader
.
ptr
.
start
(
request
)).
response
;
mojom
.
UrlResponse
response
=
(
await
loader
.
ptr
.
start
(
request
)).
response
;
if
(
require200
&&
(
response
.
error
!=
null
||
response
.
statusCode
!=
200
))
{
StringBuffer
message
=
new
StringBuffer
();
message
.
writeln
(
'Could not
${request.method ?? "fetch"}
${request.url ?? "resource"}
'
);
if
(
response
.
error
!=
null
)
message
.
writeln
(
'Network error:
${response.error.code}
${response.error.description ?? "<unknown network error>"}
'
);
if
(
response
.
statusCode
!=
200
)
message
.
writeln
(
'Protocol error:
${response.statusCode}
${response.statusLine ?? "<no server message>"}
'
);
if
(
response
.
url
!=
request
.
url
)
message
.
writeln
(
'Final URL after redirects was:
${response.url}
'
);
throw
message
;
}
return
response
;
}
catch
(
e
)
{
print
(
"NetworkService unavailable
$e
"
);
return
new
UrlResponse
()..
statusCode
=
500
;
}
catch
(
exception
)
{
debugPrint
(
'-- EXCEPTION CAUGHT BY NETWORKING HTTP LIBRARY -------------------------'
);
debugPrint
(
'An exception was raised while sending bytes to the Mojo network library:'
);
debugPrint
(
'
$exception
'
);
debugPrint
(
'------------------------------------------------------------------------'
);
return
null
;
}
finally
{
loader
.
close
();
}
}
Future
<
UrlResponse
>
fetchUrl
(
String
relativeUrl
)
{
Future
<
mojom
.
UrlResponse
>
fetchUrl
(
String
relativeUrl
,
{
bool
require200:
false
}
)
{
String
url
=
Uri
.
base
.
resolve
(
relativeUrl
).
toString
();
UrlRequest
request
=
new
UrlRequest
()
mojom
.
UrlRequest
request
=
new
mojom
.
UrlRequest
()
..
url
=
url
..
autoFollowRedirects
=
true
;
return
fetch
(
request
);
return
fetch
(
request
,
require200:
require200
);
}
packages/flutter/lib/src/services/image_cache.dart
View file @
a3b17838
...
...
@@ -52,15 +52,14 @@ class _UrlFetcher implements ImageProvider {
@override
Future
<
ImageInfo
>
loadImage
()
async
{
UrlResponse
response
=
await
fetchUrl
(
_url
);
if
(
response
.
statusCode
>=
400
)
{
print
(
"Failed (
${response.statusCode}
) to load image
$_url
"
);
return
null
;
UrlResponse
response
=
await
fetchUrl
(
_url
,
require200:
true
);
if
(
response
!=
null
)
{
return
new
ImageInfo
(
image:
await
decodeImageFromDataPipe
(
response
.
body
),
scale:
_scale
);
}
return
new
ImageInfo
(
image:
await
decodeImageFromDataPipe
(
response
.
body
),
scale:
_scale
);
return
null
;
}
@override
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment