Skip to content

_api error handling

Chris Lowth edited this page Sep 21, 2022 · 3 revisions

API Error handling

Errors returned by Turbonomic in response to API requests made by the tool result in exceptions being thrown by the client API functions. You can catch these using JavaScript's try/catch syntax. You can also obtain details of the error body (if it was in a JSON format) using client.lastException(). This typically returns an object with two or three fields (type [integer], exception [string] and optionally: message [string]).

try {
  var opts = {
    q: "",
    types: args[0]
  }
  var rtn = client.getSearchResults(opts)
} catch (err) {
  eprintln("ERROR : "+err);
  eprintln(client.lastException().message)
}
Clone this wiki locally