Handling different response scenarios

18 views
Skip to first unread message

Rick Mann

unread,
Oct 19, 2016, 10:23:46 PM10/19/16
to Baratine
Modeling my user registration method after that in Auction, I've got this:

https://github.com/JetForMe/hoa/blob/master/src/main/java/com/latencyzero/hoa/AbstractHOASession.java?ts=4#L44

But I don't see how to return an HttpStatus of 409 (CONFLICT) in the case. In addition, I want to return a completely different JSON response than the one afforded by UserPublic (something indicating the error during registration).

Is that even possible?



--
Rick Mann
rm...@latencyzero.com


Alex Rojkov

unread,
Oct 19, 2016, 10:45:01 PM10/19/16
to Rick Mann, Baratine
Yep, sending errors is possible though this case requires a more
general UserCreateResponse object that should either contain a
UserPublic if the operation completed successfully, or exception. The
cases should be distinguished by the status code that I'd recommend be
included in UserCreateResponse and be a business specific error as
opposed to http status.

Alex
> --
> You received this message because you are subscribed to the Google Groups "Baratine" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to baratine-io...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Rick Mann

unread,
Oct 19, 2016, 10:47:16 PM10/19/16
to Alex Rojkov, Baratine
That's not very RESTful. A 409 CONFLICT is a good response when trying to create two users with the same ID.

Similarly, I want to send 201 CREATED when user registration is successful.
--
Rick Mann
rm...@latencyzero.com


Alex Rojkov

unread,
Oct 19, 2016, 10:51:23 PM10/19/16
to barat...@googlegroups.com, rm...@latencyzero.com
I see where you are going. Try sending null in OK and set the status to 409.
>>> To unsubscribe from this group and stop receiving emails from it, send an email to baratine-io+unsubscribe@googlegroups.com.

Rick Mann

unread,
Oct 19, 2016, 10:53:18 PM10/19/16
to Alex Rojkov, Baratine
I don't see any way to set the status on a Result<UserPublic>. It's only on RequestWeb, as far as I can see.

> On Oct 19, 2016, at 19:51 , Alex Rojkov <roj...@gmail.com> wrote:
>
> I see where you are going. Try sending null in OK and set the status to 201.
>
> On Wed, Oct 19, 2016 at 7:47 PM, Rick Mann <rm...@latencyzero.com> wrote:
>> That's not very RESTful. A 409 CONFLICT is a good response when trying to create two users with the same ID.
>>
>> Similarly, I want to send 201 CREATED when user registration is successful.
>>
>>> On Oct 19, 2016, at 19:44 , Alex Rojkov <roj...@gmail.com> wrote:
>>>
>>> Yep, sending errors is possible though this case requires a more
>>> general UserCreateResponse object that should either contain a
>>> UserPublic if the operation completed successfully, or exception. The
>>> cases should be distinguished by the status code that I'd recommend be
>>> included in UserCreateResponse and be a business specific error as
>>> opposed to http status.
>>>
>>> Alex
>>>
>>>
>>> On Wed, Oct 19, 2016 at 7:23 PM, Rick Mann <rm...@latencyzero.com> wrote:
>>>> Modeling my user registration method after that in Auction, I've got this:
>>>>
>>>> https://github.com/JetForMe/hoa/blob/master/src/main/java/com/latencyzero/hoa/AbstractHOASession.java?ts=4#L44
>>>>
>>>> But I don't see how to return an HttpStatus of 409 (CONFLICT) in the case. In addition, I want to return a completely different JSON response than the one afforded by UserPublic (something indicating the error during registration).
>>>>
>>>> Is that even possible?
>>>>
>>>>
>>>>
>>>> --
>>>> Rick Mann
>>>> rm...@latencyzero.com
>>>>
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google Groups "Baratine" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send an email to baratine-io...@googlegroups.com.
>>>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>> --
>> Rick Mann
>> rm...@latencyzero.com
>>
>>


--
Rick Mann
rm...@latencyzero.com


Alex Rojkov

unread,
Oct 19, 2016, 10:54:45 PM10/19/16
to Rick Mann, Baratine
Right, I assumed that was RequestWeb. It needs to be RequestWeb if you
were to change the status.
Reply all
Reply to author
Forward
0 new messages