# Server side exceptions & errors handling

**URL:** <https://discuss.akka.io/t/server-side-exceptions-errors-handling/3658>\
**Category:** Akka gRPC\
**Created:** [March 13, 2019, 10:04pm UTC](https://discuss.akka.io/t/server-side-exceptions-errors-handling/3658 "2019-03-13T22:04:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![otm](https://avatars.discourse-cdn.com/v4/letter/o/bc79bd/32.png) [@otm](https://discuss.akka.io/u/otm)\
**Post date:** [March 13, 2019, 10:04pm UTC](https://discuss.akka.io/t/server-side-exceptions-errors-handling/3658/1 "2019-03-13T22:04:50Z")

</div>

Hi,

In server side how can I implemante exceptions/errors handling in order to return response with associated return code ([as described here](https://cloud.google.com/apis/design/errors?hl=fr#handling_errors)) and a custom error message?

In java-grpc we can have

```auto
responseBuilder.setResponseCode(400).setMessage("Service Failed and so and so ...");
return responseBuilder.build();

```

But in akka-grpc I found that I can throws an exception  
`throw new GrpcServiceException(Status.FAILED_PRECONDITION)`

I’m not sure it’s the right way.

Please, any idea or example how can I do it ?

Tks

---

<div class="post-metadata">

**Author:** ![chbatey](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/chbatey/32/98_2.png) [@chbatey](https://discuss.akka.io/u/chbatey)\
**Post date:** [March 18, 2019, 11:41am UTC](https://discuss.akka.io/t/server-side-exceptions-errors-handling/3658/2 "2019-03-18T11:41:13Z")

</div>

For Akka gRPC you are either working with a `CompletableFuture/Future` or an Akka Stream, both of which can complete with failure. E.g. an exception thrown within a `Future` or `Future.failed`. This should be preferred to throwing an exception from the Service implementation however I believe that will work as Akka gRPC internally will call your service from a Future or Stream.
