Skip to content

Improve error handling and optimize character lookup #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,7 @@ app.use(express.static(path.join(__dirname, 'public')));
app.locals.delimiters = '{{ }}';

function getCharacterByName(name) {
for(let i=0; i< json.length; i++) {
if(json[i].name == name) {
return json[i];

}
}
return null;
return json.find(character => character.name === name) || null;
}

// Route to send the prompt
Expand Down Expand Up @@ -74,8 +68,8 @@ app.post('/send', async (req, res) => {
answer: completion.choices[0]?.message?.content
});
} catch (error) {
console.log(`Error: ${error}`);
res.status(500).json({ error: error });
console.error(`Error: ${error.message}`); // Log the error message for debugging
res.status(500).json({ message: 'An unexpected error occurred. Please try again later.' }); // Send a generic error message
}
});

Expand Down