Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

In a gadget, how do you modify the error shown?

Jannik Luyten
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 3, 2013

Hi fellow developers

I am creating an atlassian gadget which calls a rest service to do some magic. When the magic fails, the rest service throws an error which I can visualise and style myself, however, the default error message is also shown in it's own pretty error box (see below).

Is it possible to either not show the default message, or put my own message in this pretty error box?

Kind regards

Jannik

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Jannik Luyten
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 10, 2013

I learned through debugging the ajs.gadget.configurable.js file, that there is different behaviour depending on the status code returned by the REST service. Two things happen: 1) the AJS framework picks up the response and handles it according to its status code and 2) the AJAX rest call ends up in the error function (if specified) of your own code .

The first action seems to be out of our controle, i.e. a red error box will be shown upon receiving a 500 response, whether you like it or not. It seems to be up to the developer to return a more appropriate status code if this is not desired.

The following actions are performed by the AJS framework upon receiving either of the following status codes:

* 500 and the error box is shown containing the message "internal server error".
* 400 and a blue box is shown containing one or more "validation failed" messages according to the content of the response (https://developer.atlassian.com/display/GADGETS/REST+Resource+for+Validating+Gadget+Configuration).

I found that the documentation regarding the handling of exceptions thrown by rest services in Atlassian gadgets, was a bit slim, and it took me a bit of digging to understand what was going on.

1 vote
codelab expert
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 4, 2013

Try something like that:

AJS.$.ajax({
  url: "/rest/....",
  type: "GET",
  dataType: "json",
  async: false,
  contentType: "application/json",
  error: function(jqXHR, exception) { ... do something with error ... },
  success: function(response) { ... do something with data ... }
});

Jannik Luyten
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 4, 2013

Hi Mathias

Thank you for replying. This is something I already do. In the error function, I output the exception to the gadget ("An error occured: The magic failed!" is an illegalargumentexception thrown by my rest service).

This does not remove the "Internal server error" error box however.

TAGS
AUG Leaders

Atlassian Community Events