RocketChat / Rocket.Chat.js.SDK

Utility for apps and bots to interact with Rocket.Chat via DDP and/or API
MIT License
136 stars 94 forks source link

SDK api post returns undefined when error #89

Open unexpand opened 5 years ago

unexpand commented 5 years ago

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' }

mriedmann commented 4 years ago

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

TBG-FR commented 3 years ago

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

AvivBenShoham commented 3 years ago

Did you solve it?

tolulope-od commented 2 years ago

Has anyone been able to solve this issue.