I am working on REST API and it calls another service and fetch the data and return to the UI. So It does not have any direct DB interactions. Recently we added exception handling feature which uses Controller Advice to handle the Application level exceptions. A sample response looks like below:

    "error":"Internal Server Error",
    "message":"No message available",

When ever there is an error, the UI logs the message to Splunk which alreadys logs using Timestamp. So Is there really a advantage of adding timestamp to the response? Or What other advantages do I get using this timestamp field in my response?

  • What will the client of the REST API use this timestamp for? If you cannot think of a good use, then do not include it. – Greg Burghardt Jan 11 at 16:38
  • As of now, they donot use it. – happytohelp Jan 11 at 16:39
  • To be honest, YAGNI applies here (Ya Ain't Gonna Need It). – Greg Burghardt Jan 11 at 16:40
  • Thank you. I will go through the link. Clears some confusion here. – happytohelp Jan 11 at 16:41
  • 1
    @GregBurghardt How can you possibly know that? In my experience this is one of those things that you don't need until you do need it and really wish you had done it all along. – JimmyJames Jan 11 at 16:43

There are of general ways a client can use a timestamp in the response:

  • It can help identify issues with incorrectly configured system clocks
  • It can help with identifying latency issues

The other thing I would consider here is what you will do when supporting a client when they get an error like this:

[client] I got a 500 error.

[you] when?

[client] In the middle of the night sometime?

At the very least you can use the timestamp to narrow down the search in your logs. I would recommend that you add UUID as well that you log and return to the client. This makes it a lot easier to find things.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.