Throw an error/exception if mandatory parameters are not sent to an event

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

Devops
Posts: 23
Joined: 27 May 2020, 15:23

Throw an error/exception if mandatory parameters are not sent to an event

Postby Devops » 18 Jun 2020, 13:07

I have many custom events and they require client to pass parameters to this custom event.
These parameters can be integer, string, class, sfsobject and sfsarray.

I want to check if all the required params has been passed to the event before proceeding further.
If any of the params is missing then I want to throw an error so client is aware on which parameter is missing and has to be passed.

How can this check be done in smartfox and how can a error be sent to client
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Throw an error/exception if mandatory parameters are not sent to an event

Postby Lapo » 18 Jun 2020, 14:02

Hi,
just to clarify you mean how to do this in an Extension, right?

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
Devops
Posts: 23
Joined: 27 May 2020, 15:23

Re: Throw an error/exception if mandatory parameters are not sent to an event

Postby Devops » 18 Jun 2020, 14:18

Yes these things are to be done in extension
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Throw an error/exception if mandatory parameters are not sent to an event

Postby Lapo » 18 Jun 2020, 15:18

Ok,
you can simply reply to the client with an error code (or error message) providing the details of what is missing.
From client side you can catch these codes/messages and show them to the user.

Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games
Devops
Posts: 23
Joined: 27 May 2020, 15:23

Re: Throw an error/exception if mandatory parameters are not sent to an event

Postby Devops » 18 Jun 2020, 15:29

How do I send an error code as an event response?
Do I have to send a new error event?

Is there any way to do it with the following exception?

Code: Select all

SFSException(String message)
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Throw an error/exception if mandatory parameters are not sent to an event

Postby Lapo » 19 Jun 2020, 07:39

Hi,
it's just a custom message. You decide which code or message to send from server to client and handle it on the other side.

Devops wrote:Is there any way to do it with the following exception?

Code: Select all

SFSException(String message)

No you need to use the send method to send data to the client(s):

Code: Select all

ISFSObject params = new SFSObject()
params.putInt("errCode", someCode);

send("someAction", params, targetUser);


Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 60 guests