Exception handling in gRPC - protocol-buffers

I have a server written in Java and client written in PHP. How can client catch exception from server if anything goes wrong? I can't find anything about exception handling in gRPC documentation.
Thank you!

For handled exceptions, call responseObserver.onError(). If you pass in a StatusRuntimeException or StatusException (generally created via status.asRuntimeException()) the status code and description will be communicated to the client. Unhandled exceptions within a callback will cancel the RPC and will continue propagating the exception (generally leading in an UncaughtExceptionHandler being called for the executor).

In the response at the client side (php)
http://www.grpc.io/grpc/php/source-class-Grpc.UnaryCall.html#82
the status here will have the code and details fields which will determine the response code and the appropriate message if set as mentioned in Eric's response. Based on that appropriate error handling can be done at the client.

Related

Quarkus is hiding resteasy exceptions

I have run into a fairly annoying problem with Quarkus, that I cannot figure out how to solve.
I am using quarkus 2.4.1.Final. I am using the quarkus-resteasy-reactive-jackson module to create a REST service.
But when I send the service a post body with a bad format the client simply gets an empty HTTP 400 response back, and nothing is printed in the log on the server side. In this particular case I forgot to add the offset to an OffsetDateTime, so adding "+01:00" makes the service return correctly. Using micrometer metrics, I can see that the endpoint is being hit correctly both when the request is correct and when it isn't.
Hiding an exception from the developer is very close to heresy for me, as I would like to be able to see what the server fails with. I understand that we don't want the stack trace on the client side, but in this case the exception is missing from the server log.
Can anyone help me to convince Quarkus to not swallow my exceptions?

How to implement a retry SOAP request flow if the first try fails

I'm working with Websphere Message Broker V8.0, I have the next flow for a simple SOAP mediation:
SOAP Input -> SOAP request -> Soap Extract -> Compute Node -> SoapReply
Is there any logic that can be applied to this flow if a request fails? (timeout, system error, intermittent service)
thanks in advance.
A possible solution to your problem could be:
Connecting both the failure terminal of your SOAP Request node to a flow that could route to the input of the SOAP Request when certain failures occur and putting a TryCatch node before and after the SOAP Request to have a separated error handling region, while connecting the fault output of the SOAP Request to a Throw node to raise exceptions when faults occur and have an error handler subflow connected to the catch terminal of the TryCatch before the SOAP Request to route to the input terminal of the SOAP Request.
As you can see, you will need to implement the error handling logic required for your application, Message Broker provides only the framework for it. So first of all you should familiarize yourself with the error handling capabilities of the message flows:
http://www-01.ibm.com/support/knowledgecenter/SSMKHH_9.0.0/com.ibm.etools.mft.doc/ac00410_.htm

What should be the Http Server code for Validation Error happening in server?

When an action is called by the client to server say POST/PUT, there would be some validations happening in the data that needs to be processed. But that data doesn't comes as a request, data would be fetched from DB (coz the endpoint clearly knows what it should do, so I dont tell the service what to update) and on top of that, validations would be performed.
So if any validation fails on such data, what should be the response code that should be returned?
Am sceptical to use 4XX codes, since those codes are reserved for the errors produced by client.
In my case, since client does not produce any error, what should be the response code for these kind of validation errors?
If your service returns an error which is definetly not caused by the user's request data rather than from the data/state of the server, the service should respond with HTTP 500 Internal Server Error. There is no specific Internal Server Validation Error status code in RFC2616/RFC7231, so I recommend to take the 'general' 500 status.
From RFC 7231:
The 500 (Internal Server Error) status code indicates that the server encountered an unexpected condition that prevented it from fulfilling the request.

How to add the unhandled exceptions accross the applications in response body in WEB API

How to add the unhandled exceptions accross the applications in response body in WEB API. If there is no exceptions a success message needs to be sent to the response body for all the responses....Need help on achieving this.
You need two things. For handling the exceptions, you need to set the IncludeDetailErrorPolicy in the HttpConfiguration object,
You can configure the error policy preferences as part of the configuration object (HttpConfiguration) in the IncludeErrorDetailPolicy property. This is just an enum that instructs Web API about how to deal with exceptions.
The possible values for this enum are,
Default: It’s uses the customErrors configuration settings if you are using ASP.NET as host or LocalOnly for self-host.
LocalOnly: Only includes error details for local requests
Always: Always includes error details
Never: Never includes error details
When an exception happens, Web API will check the value on this setting for including details about the exception in the response message or not. For example, if Always is enabled, Web API will serialize the exception details as part of the message that you get as response.
The success message does not make much sense as you already have the response status code. A status code equals to OK means that everything went ok. If you still want to add an additional message, use a HttpMessageHandler that checks for the response status code. If the status code is OK, add the message. However, the response body has been set already at that point so you will not able to modify it. You might able to add a message as a header.

What does this gSoap fault message mean?

I am using gSoap to communicate with the web service. I am using Qt to create application that uses gSoap. I am getting following fault message for some of the calls
SOAP 1.1 fault: "http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher":DeserializationFailed[no subcode]
"The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'GetPendingCommands'. Unexpected end of file. Following elements are not closed: Body, Envelope. Line 2, position 459."
Can someone please explain me what could be wrong with the service?
Thanks
DPatel
If chunking is turned on in your client side code, try turning it off. I seem to recall that you have to do something special with gSoap to get it to support chunking on the server side.
The error message means the client has received a truncated SOAP envelope. This often happens if the web service neglects to flush its output buffer before returning.

Resources