const Course = require("../models/course.model");
In here code is usually working but when it facing an error it wont show proper error message in run time also it didnt show error in the console
const addCourse = async(ctx) => {
try {
console.log(ctx.request.body);
const {courseName, courseFee, students} = ctx.request.body;
const course = await Course.create({
courseName,
courseFee,
students})
// return (ctx.body = {course: course});
return (ctx.body = course);
} catch (error) {
return (ctx.body ={ message : message})
}
also in the get function is working but when error comes out it didn’t
show like in below code
const getCourses = async(ctx) =>{
try {
const courses = await Course.find({}).populate({
path: "students",
select : "name nic",
})
// return (ctx.body ={courses: courses})
return (ctx.body =courses)
} catch (error) {
return (ctx.body = { message : message})
}
}
same thing happened
const updateCourse = async(ctx)=>{
try {
const courseId = ctx.params.id;
const {courseName,courseFee,students} = ctx.request.body;
const course = await Course.findByIdAndUpdate(courseId,{courseName,courseFee,students})
return (ctx.body = course);
} catch (error) {
return (ctx.body ={ message : error.message})
}
}
>Solution :
In all of these functions you haven’t return the error message
properly
return (ctx.body ={ message : error.message})
hope this helps