Skip to content

Unfriendly Error Message on Updating Non-Existent Marketing Event via PUT /api/v1/settings/marketing/events/{id} #153

Description

@sagarkumar-webkul

Title:

Unfriendly Error Message on Updating Non-Existent Marketing Event via PUT /api/v1/settings/marketing/events/{id}

Description:

When sending a PUT request to update a marketing event using a non-existent ID, the API returns a 404 response with a verbose Laravel exception message. This is not user-friendly and should be handled gracefully with a clear, concise message.

Affected Endpoint:

  • PUT /api/v1/settings/marketing/events/{id}

Preconditions:

  • Krayin REST API is up and authenticated.
  • Event with the provided ID does not exist in the database.

Steps to Reproduce:

  1. Send a PUT request to /api/v1/settings/marketing/events/45 (assuming ID 45 does not exist).
  2. Include a valid JSON payload in the request body.
  3. Observe the response.

Actual Result:

Image
{
  "message": "No query results for model [Webkul\\Marketing\\Models\\Event] 45",
  "exception": "Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException",
  ...
}

Expected Result:

{
  "message": "Marketing event with ID 45 not found.",
  "status": 404
}

Suggested Fix:

  • Catch ModelNotFoundException in the controller or middleware.
  • Return a clean 404 JSON response instead of a stack trace.
  • Ensure APP_DEBUG=false in production to avoid leaking internal paths.

Benefit:

  • Provides a proper API experience for developers.
  • Aligns with RESTful standards.
  • Prevents exposure of internal Laravel implementation details.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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