Skip to content

Internal Server Error (500) When Fetching Non-Existent Marketing Event /api/v1/settings/marketing/events/{id} #152

Description

@sagarkumar-webkul

Title:

Internal Server Error (500) When Fetching Non-Existent Marketing Event /api/v1/settings/marketing/events/{id}

Description:

When attempting to fetch a marketing event using an invalid or non-existent ID, the API returns a 500 Internal Server Error with the message:
"Attempt to read property 'id' on null".

This is misleading and exposes internal error handling issues instead of providing a clean API response.

Affected Endpoint:

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

Preconditions:

  • Krayin REST API is installed and authenticated.
  • Marketing event with the specified ID does not exist.

Steps to Reproduce:

  1. Send a GET request to /api/v1/settings/marketing/events/12 (assuming ID 12 does not exist).
  2. Observe the response.

Actual Result:

Image
  • HTTP 500 Internal Server Error
{
  "message": "Attempt to read property 'id' on null",
  "exception": "ErrorException",
  ...
}

Expected Result:

  • HTTP 404 Not Found
{
  "message": "Marketing event with ID 12 not found.",
  "status": 404
}

Suggested Fix:

  • Check if the marketing event exists before trying to access properties.
  • Catch ModelNotFoundException or explicitly return a 404 when the record is not found.
  • Ensure Laravel debug mode (APP_DEBUG) is disabled in production to prevent stack trace exposure.

Benefit:

  • Provides a clean and accurate error message to API consumers.
  • Prevents exposure of internal application logic.
  • Aligns with standard REST API practices.

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