Rocket.Chat.js.SDK icon indicating copy to clipboard operation
Rocket.Chat.js.SDK copied to clipboard

SDK api post returns undefined when error

Open unexpand opened this issue 6 years ago • 4 comments

When using SDKs API, I make a post request. Tried async / await as well but no way can I get a handle error returned by request.

api .post("users.create", { name: data.name, email: data.email, password: data.password, username: data.username, roles: ["anonymous"] }) .then(res => console.log(res)) .catch(error => console.error(error));

I get the following error on logs generated by API but no way can I get a handle on error thrown, all I get is undefined.

[API] POST error (users.create): { success: false, error: 'ajskajs is already in use :( [error-field-unavailable]', errorType: 'error-field-unavailable' }

unexpand avatar Aug 12 '19 17:08 unexpand

Looks like the same problem i had months ago: https://github.com/RocketChat/Rocket.Chat.js.SDK/pull/79

mriedmann avatar Oct 11 '19 05:10 mriedmann

I have the same issue, using hubot-rocketchat which is just a "bridge" to the SDK

Code

const addedUser = await robot.adapter.api.post('users.create', { email, name, password, username });

console.log(addedUser);  

Logs

 ERROR [API] POST error (users.create): { success: false,
  error: 'Adding user is not allowed [error-action-not-allowed]',
  errorType: 'error-action-not-allowed',
  details: { method: 'insertOrUpdateUser', action: 'Adding_user' } }

undefined

I didn't added the permission to my bot, so it's normal that I get success = false, but I can't handle the error as I get and undefined object

TBG-FR avatar Oct 01 '20 09:10 TBG-FR

Did you solve it?

AvivBenShoham avatar Jan 12 '21 13:01 AvivBenShoham

Has anyone been able to solve this issue.

tolulope-od avatar Oct 06 '21 20:10 tolulope-od