PHP

Fixing Portfolio CV Generation in Landing Project

The landing project focuses on creating a smooth user experience for generating portfolios.

The Problem

The portfolio CV generation process was failing due to two key issues:

  1. The role_name field, required by the backend validation, was not being sent from the portfolio modal.
  2. The Accept header was incorrectly set to application/pdf instead of application/json. This caused the server to return validation errors as HTML redirects, which the fetch() function then interpreted as corrupted files.

The Solution

The fix involved addressing both of these problems:

  • Ensuring the role_name is correctly sent from the portfolio modal.
  • Setting the Accept header to application/json to receive validation errors in the correct format.
  • Removal of PDF format selector. The backend only generates DOCX files.

This ensures that the client correctly requests and receives data from the server. Here's a simplified example of how the fetch request might be structured:

$data = array(
    'role_name' => 'Software Engineer'
);

$options = array(
    'http' => array(
        'method'  => 'POST',
        'header'  => array(
            'Content-type: application/x-www-form-urlencoded',
            'Accept: application/json'
        ),
        'content' => http_build_query($data)
    )
);

$context  = stream_context_create($options);
$result = file_get_contents('https://example.com/generate-cv', false, $context);
if ($result === FALSE) { /* Handle error */ }

$response = json_decode($result);

if (isset($response->error)) {
    // Handle validation errors
} else {
    // Process the successful response
}

Key Takeaways

  • Always ensure that the client sends all required data to the server.
  • Verify that the Accept header is set correctly to match the expected response format.
  • Handle server-side validation errors gracefully on the client-side.
Fixing Portfolio CV Generation in Landing Project
GERARDO RUIZ

GERARDO RUIZ

Author

Share: