How get updateAsync response error information beyond the string description

I am just getting started with the ShapeDiver API (using viewer.shapediver.com/v2/2.23.0) and thought I would explore how it responds to invalid parameters conveyed via parameters.updateAsync. I want to be able to provide users of my custom UI with as much info as possible on their errors.

So I hacked the code to deliberately set a parameter to 42 (invalid), just to try out the S/D error responses. I see great information in the console, printed from LoggingMixin:73

[Error] ERROR.ApiImplementationV2.ParameterApi.updateAsync – “:” – “_parameterHandler.setMultipleParameterValues returned error”
Object
err: [{code: “value_reject”, msg: “Parameter value rejected”, data: 42}] (1)
params: [{id: “395b01e3-369f-4dba-b02a-aa35f4afee60”, plugin: “CommPlugin_1”, result: “value_reject”}] (1)
plugins: {}
token: {id: “h8o6cwqlvb”, serial: 1616423846822, payload: undefined, attributes: undefined}

But from JS, response.err.data object does not seem helpful.

[Error] error response err data
Error: [object Object]
ApiResponse$$module$src$api$v2$ApiResponse — ApiResponse.js:70
(anonymous function) — ApiResponse.js:99
e — ApiParameterImplementationV2.1.js:151
(anonymous function) — ApiParameterImplementationV2.1.js:171
Promise
(anonymous function) — ApiParameterImplementationV2.1.js:115
(anonymous function) — index.html:136
(anonymous function) (index.html:158)
promiseReactionJob

I suspect a “JS for Dummies” is in my future :slight_smile: but I have not figured out how to get more info out of response.err.data. Any tips welcome.

Forgot the code:

paramInput.onchange = function() {
let paramID = spec_id_to_param_id(spec.id);
let new_value = (this.value==0) ? 42 : this.value;
clg(‘param change’, this.id, this.value, new_value, spec.name);
api.parameters.updateAsync({
id: paramID,
value: new_value
}).then(
function(response) {
// here we could offer user errors for selections
// that do not pan out in the model
console.log(“param update response”, response);
console.log(“type,keys response”, typeof(response), Object.keys(response));
console.log(“resp.data”, response.data);
if ( response.data) {
clg(‘response OK’, response.data);
}

    if (response.err) {
      console.log("response err to string", response.err.toString());
      console.log("response err  message", response.err.message);
      console.log("response err  name", response.err.name);
      console.error( "response error", response.err);
      clg("response err keys", Object.keys(response.err));
      // clg(" response err data typeof/keys", 
      //   typeof(response.err.data), Object.keys( response.err.data));
      console.error("error response err data", response.err.data);
      console.log("log response err data", response.err.data);

    }
  }).catch(err => { console.log("uAsync caught!", err) });

};

I’m not sure if I understand your use case correctly but you can create custom sliders with correct value range from the model parameters so your users can’t go wrong, see this example.

Does this work for you?

Thanks for the thought. Well, I am new to SD and GH so maybe this is not a problem, but my concern is that we will not be able to head off all modeling errors with restricted input elements. For example, can each of two inputs be valid in themselves, but the combination be invalid together?

Also, we do see full error information including the parameter ID in the console. I am hoping my application can get that same info programmatically.

Just to be clear, this will be general purpose tool that can be used for any given GH model, so I have to code for general cases. Hope that explains better the need.

I understand now what you want to achieve. Unfortunately, the promises don’t return meaningful errors at the moment but this issue will be resolved with upcoming viewer upgrades later this year.

I can’t imagine a case when a combination of two valid parameters would be invalid. However, some parameter combinations of a model can sometimes lead to timeout errors if the solution can’t be calculated due to computation time limit or complexity of meshes. Learn more about the output limits and platform error messages below:

Glad to hear this will be rectified soon. Thx!