diff options
author | Christoph Helma <helma@in-silico.ch> | 2012-03-06 10:59:11 +0000 |
---|---|---|
committer | Christoph Helma <helma@in-silico.ch> | 2012-03-06 10:59:11 +0000 |
commit | 7588adffdbd48a73d8b22be2379a5afee79e5bea (patch) | |
tree | 08c0468626666d7f96d749b9ced55a34a8a35298 | |
parent | a5f8c658ba87a00950766182966b65c65d5e2b66 (diff) |
backtick operator overwrite to catch system call errors
-rw-r--r-- | lib/error.rb | 16 | ||||
-rw-r--r-- | lib/task.rb | 1 |
2 files changed, 15 insertions, 2 deletions
diff --git a/lib/error.rb b/lib/error.rb index 29f4234..81ec979 100644 --- a/lib/error.rb +++ b/lib/error.rb @@ -24,10 +24,11 @@ module OpenTox "BadRequestError" => 400, "NotAuthorizedError" => 401, "NotFoundError" => 404, - "ServiceUnavailableError" => 503, - "TimeOutError" => 504, "LockedError" => 423, + "InternalServerError" => 500, "NotImplementedError" => 501, + "ServiceUnavailableError" => 503, + "TimeOutError" => 504, }.each do |klass,code| # create error classes c = Class.new Error do @@ -115,6 +116,17 @@ module OpenTox end end + # overwrite backtick operator to catch system errors +class Object + def `(code) + msg = super("#{code} 2>&1").chomp + internal_server_error msg unless $?.to_i == 0 + msg + rescue Errno::ENOENT => e + internal_server_error e + end +end + class Array def short_backtrace short = [] diff --git a/lib/task.rb b/lib/task.rb index d7ad539..3a52dee 100644 --- a/lib/task.rb +++ b/lib/task.rb @@ -10,6 +10,7 @@ module OpenTox def self.create service_uri, params={} # TODO set/enforce request uri + # TODO: run observer in same process? task = Task.new RestClientWrapper.post(service_uri,params).chomp pid = fork do begin |