kchilek
Posts: 0
Joined: Tue Feb 21, 2017 3:09 am

Incorrect error code when using DatabaseUser.update

I am trying to capture the correct error message when a user trys to update their username with an already existing one.

var username = request.get("username");
var user_id = request.get("user_id");
var email = request.get("email");
var userToken = request.headers["X-Appery-Session-Token"];

var user = DatabaseUser.update(db_id, user_id,{"username":username,"email": email},userToken);

Apperyio.response.success(user, "application/json");

The error I receive is: Error code SCSE014: Script execution failed. Details have been added to Trace tab.

In the trace I get: 26.2.2017, 1:40:06 AM: Script updateUser: ApperyioAPI: User 'kchilek2' already exists in database.

How do I get the message from the trace?

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Incorrect error code when using DatabaseUser.update

Hello,

Please use try-catch structure and send an error response, if the error is found:
pretry{
var user = DatabaseUser.update(
db_id,
user_id,
{"username":username,"email": email},
userToken
);
} catch(e){
Apperyio.response.error(
{error: e.toString()},
"application/json"
);
}/pre

Return to “Issues”