[rygel] core: Better error handling
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [rygel] core: Better error handling
- Date: Sun, 4 Oct 2009 00:52:13 +0000 (UTC)
commit 25e0d78ad42083f26dae3fa52ad97bac15510c66
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Sun Oct 4 03:33:04 2009 +0300
core: Better error handling
- HTTPRequestHandler.add_resource should throw generic error.
- Nicely handle (translate to HTTPRequestError) all generic errors.
src/rygel/rygel-http-identity-handler.vala | 32 ++++++++++++++++----------
src/rygel/rygel-http-request-handler.vala | 17 +++++++++-----
src/rygel/rygel-http-transcode-handler.vala | 20 ++++++++++------
3 files changed, 43 insertions(+), 26 deletions(-)
---
diff --git a/src/rygel/rygel-http-identity-handler.vala b/src/rygel/rygel-http-identity-handler.vala
index 5ff12f6..785a66a 100644
--- a/src/rygel/rygel-http-identity-handler.vala
+++ b/src/rygel/rygel-http-identity-handler.vala
@@ -66,6 +66,26 @@ internal class Rygel.HTTPIdentityHandler : Rygel.HTTPRequestHandler {
public override HTTPResponse render_body (HTTPRequest request)
throws HTTPRequestError {
+ try {
+ return this.render_body_real (request);
+ } catch (Error err) {
+ throw new HTTPRequestError.NOT_FOUND (err.message);
+ }
+ }
+
+ protected override DIDLLiteResource add_resource (DIDLLiteItem didl_item,
+ HTTPRequest request)
+ throws Error {
+ var protocol = request.http_server.get_protocol ();
+
+ if (request.thumbnail != null) {
+ return request.thumbnail.add_resource (didl_item, protocol);
+ } else {
+ return request.item.add_resource (didl_item, null, protocol);
+ }
+ }
+
+ private HTTPResponse render_body_real (HTTPRequest request) throws Error {
if (request.thumbnail != null) {
return new SeekableResponse (request.server,
request.msg,
@@ -104,16 +124,4 @@ internal class Rygel.HTTPIdentityHandler : Rygel.HTTPRequestHandler {
this.cancellable);
}
}
-
- protected override DIDLLiteResource add_resource (DIDLLiteItem didl_item,
- HTTPRequest request)
- throws HTTPRequestError {
- var protocol = request.http_server.get_protocol ();
-
- if (request.thumbnail != null) {
- return request.thumbnail.add_resource (didl_item, protocol);
- } else {
- return request.item.add_resource (didl_item, null, protocol);
- }
- }
}
diff --git a/src/rygel/rygel-http-request-handler.vala b/src/rygel/rygel-http-request-handler.vala
index a99335a..f958c22 100644
--- a/src/rygel/rygel-http-request-handler.vala
+++ b/src/rygel/rygel-http-request-handler.vala
@@ -45,12 +45,17 @@ internal abstract class Rygel.HTTPRequestHandler: GLib.Object {
// something better, be my guest and provide a patch.
var didl_writer = new GUPnP.DIDLLiteWriter (null);
var didl_item = didl_writer.add_item ();
- var resource = this.add_resource (didl_item, request);
- var tokens = resource.protocol_info.to_string ().split (":", 4);
- assert (tokens.length == 4);
+ try {
+ var resource = this.add_resource (didl_item, request);
+ var tokens = resource.protocol_info.to_string ().split (":", 4);
+ assert (tokens.length == 4);
- request.msg.response_headers.append ("contentFeatures.dlna.org",
- tokens[3]);
+ request.msg.response_headers.append ("contentFeatures.dlna.org",
+ tokens[3]);
+ } catch (Error err) {
+ warning ("Received request for 'contentFeatures.dlna.org' but " +
+ "failed to provide the value in response headers");
+ }
}
// Create an HTTPResponse object that will render the body.
@@ -59,5 +64,5 @@ internal abstract class Rygel.HTTPRequestHandler: GLib.Object {
protected abstract DIDLLiteResource add_resource (DIDLLiteItem didl_item,
HTTPRequest request)
- throws HTTPRequestError;
+ throws Error;
}
diff --git a/src/rygel/rygel-http-transcode-handler.vala b/src/rygel/rygel-http-transcode-handler.vala
index 782994f..0ca6bf3 100644
--- a/src/rygel/rygel-http-transcode-handler.vala
+++ b/src/rygel/rygel-http-transcode-handler.vala
@@ -57,19 +57,23 @@ internal class Rygel.HTTPTranscodeHandler : HTTPRequestHandler {
throw new HTTPRequestError.NOT_FOUND ("Not found");
}
- src = this.transcoder.create_source (item, src);
+ try {
+ src = this.transcoder.create_source (item, src);
- return new LiveResponse (request.server,
- request.msg,
- "RygelLiveResponse",
- src,
- request.time_range,
- this.cancellable);
+ return new LiveResponse (request.server,
+ request.msg,
+ "RygelLiveResponse",
+ src,
+ request.time_range,
+ this.cancellable);
+ } catch (GLib.Error err) {
+ throw new HTTPRequestError.NOT_FOUND (err.message);
+ }
}
protected override DIDLLiteResource add_resource (DIDLLiteItem didl_item,
HTTPRequest request)
- throws HTTPRequestError {
+ throws Error {
return this.transcoder.add_resource (didl_item,
request.item,
request.http_server);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]