[yast-devel] WebYast: Error reporting in backend and how to use it in plugin
Hi, I done error reporting in backend based on exceptions (Universal exceptions is in file exceptions in webservice/lib). There is two type of error: First is invalid or missing parameters. For this case exist InvalidParameters exceptions. For example usage and details please see documentation of this exceptions. After you throw it, then if you don't catch it, it response 422 and use Error reporting structure for ActiveResource. So it return false on ActiveResource#save see ActiveResource::Base documentation for details (section validations errors). Second is problem on target machine like missing file, failed call of script, missing permissions etc. For this case exist ancestor BackendError which if not catched response 503 and serialized xml with description of problem (exceptions.rb contains few child for inspiration). If you don't catch error on frontend it end up in error reporting page which print error. For translated error is neccesarry to add translated string to ErrorConstructor module in libs directory at frontend (see already translated messages for usage). If you have any question, suggestion or problem please say it -- Josef Reidinger YaST team maintainer of perl-Bootloader, YaST2-Repair, webyast modules language and time -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
On Mon, Sep 21, 2009 at 11:35:46AM +0200, Josef Reidinger wrote:
Hi, I done error reporting in backend based on exceptions (Universal exceptions is in file exceptions in webservice/lib).
Thanks! Here comes the punishment ;-)
There is two type of error: First is invalid or missing parameters. For this case exist InvalidParameters exceptions. For example usage and details please see documentation of this exceptions.
ENOURL! http://git.opensuse.org/?p=projects/yast/rest-service.git;a=blob;f=webservic... So as an example, which everyone will need to copy: http://git.opensuse.org/?p=projects/yast/rest-service.git;a=commitdiff;h=b7f... root = params[:time] if root == nil - render ErrorResult.error(404, 2, "format or internal error") and return + raise InvalidParameters.new [{:name => "Timezone", :error => "Missing"}] end Why is it "Timezone" instead of "time"? AFAIK :name is supposed to be the missing attribute, but here the entire record is missing. Should it not be added to the "base"? (And I don't like the need to specify an array explicitly, but I can fix that later.) -- Martin Vidner, YaST developer http://en.opensuse.org/User:Mvidner Kuracke oddeleni v restauraci je jako fekalni oddeleni v bazenu -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
On Monday 21 September 2009 12:10:24 Martin Vidner wrote:
On Mon, Sep 21, 2009 at 11:35:46AM +0200, Josef Reidinger wrote:
Hi, I done error reporting in backend based on exceptions (Universal exceptions is in file exceptions in webservice/lib).
Thanks! Here comes the punishment ;-)
There is two type of error: First is invalid or missing parameters. For this case exist InvalidParameters exceptions. For example usage and details please see documentation of this exceptions.
ENOURL! http://git.opensuse.org/?p=projects/yast/rest-service.git;a=blob;f=webservi
ce/lib/exceptions.rb;h=6dca0f4370aea170706f015a2366bb4cf5ef7c3a;hb=HEAD#l28
I think documentation of webservice, you can generate it by rake doc:app ( I hope hudson start building our documentation).
So as an example, which everyone will need to copy: http://git.opensuse.org/?p=projects/yast/rest-service.git;a=commitdiff;h=b7 f10188520c38d9a48db7b9e42f497408c8cd44 root = params[:time] if root == nil - render ErrorResult.error(404, 2, "format or internal error") and return + raise InvalidParameters.new [{:name => "Timezone", :error => "Missing"}] end
Why is it "Timezone" instead of "time"? AFAIK :name is supposed to be the missing attribute, but here the entire record is missing. Should it not be added to the "base"?
I don't enough experience with structure of error. Name is important for frontend identification of error. I plan some testing and inform mailing list.
(And I don't like the need to specify an array explicitly, but I can fix that later.)
I can fix it myself, good idea. Also this break all modules which uses basicPluginTest, because it now expect 422 on empty update request. This is for your information, that behavior change and you should also do it. -- Josef Reidinger YaST team maintainer of perl-Bootloader, YaST2-Repair, webyast modules language and time -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
Martin Vidner write:
(And I don't like the need to specify an array explicitly, but I can fix that later.)
I change it to be more DRY. So now it takes hash, which have as keys parameters and as values error identifier. so usage is: raise InvalidParameters.new :timezone => "Missing" I welcome another ideas how to improve this. -- Josef Reidinger YaST team maintainer of perl-Bootloader, YaST2-Repair, webyast modules language and time -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
participants (2)
-
Josef Reidinger
-
Martin Vidner