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:
- The
role_namefield, required by the backend validation, was not being sent from the portfolio modal. - The
Acceptheader was incorrectly set toapplication/pdfinstead ofapplication/json. This caused the server to return validation errors as HTML redirects, which thefetch()function then interpreted as corrupted files.
The Solution
The fix involved addressing both of these problems:
- Ensuring the
role_nameis correctly sent from the portfolio modal. - Setting the
Acceptheader toapplication/jsonto 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
Acceptheader is set correctly to match the expected response format. - Handle server-side validation errors gracefully on the client-side.