Skip to content

[FEATURE] Add timestamp and path fields to error response envelopes #214

@aniebietafia

Description

@aniebietafia

Problem

When the API returns an error response, the response lacks context regarding:

  1. The exact server time the error occurred (timestamp).
  2. The exact request path that triggered the error (path).

This makes troubleshooting difficult. Front-end developers or support staff report errors but cannot easily link a specific failure report to server logs without guessing the timestamp or URL.

Proposed Solution

Add timestamp and path fields to the error payload schema. If Issue 27 is implemented first, these fields will be part of the unified ApiResponse<T>. If not, update ErrorResponse.java to include these fields, and populate them in all exception handler methods using Spring's HttpServletRequest or WebRequest.

User Stories

  • As an API client, I want error payloads to contain a timestamp and request path so I can log detailed context for troubleshooting.
  • As an operations engineer, I want clients to report the exact timestamp and endpoint path from their failed API responses so I can correlate them directly to logging aggregators (e.g., Datadog, ELK).

Acceptance Criteria

  • timestamp (Instant) and path (String) fields exist in the error response JSON.
  • Timestamps are serialized using standard ISO-8601 formatting (e.g., 2026-06-20T16:44:54Z).
  • The path field returns the request URI (excluding query parameters).
  • All exception handler methods are updated to fetch and populate these fields from HttpServletRequest.

Proposed Technical Details

// If extending standard ErrorResponse before full unification:
@Data
public class ErrorResponse {
    private int statusCode;
    private String error;
    private String message;
    private String errorCode;
    private Instant timestamp;
    private String path;
}

Tasks

  • Add fields to ErrorResponse.java or verify their presence in the newly unified ApiResponse.java.
  • Inject HttpServletRequest into each exception handler method signature in GlobalExceptionHandler.java.
  • Populate timestamp with Instant.now() and path with request.getRequestURI().
  • Update Swagger docs to display the updated error response properties.

Metadata

Metadata

Assignees

No one assigned

    Labels

    apibugSomething isn't workingcidependenciesdocumentationImprovements or additions to documentationenhancementBuild on top of an already existing feature to mke it better.question

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions