NestJS มี ชั้น exception ในตัว (exception layer) ที่ดักจับ error ที่ไม่ได้จัดการโดยอัตโนมัติและแปลงเป็น HTTP response ที่เหมาะสม คุณส่งสัญญาณ error ด้วยการ throw exception (มักเป็นคลาส HTTP exception ในตัว) แล้ว Nest จะจัดรูปแบบมันเป็น JSON response ที่มีโครงสร้างพร้อม status code ที่ถูกต้อง
การ throw HTTP exception ในตัว
{ , , } ;
()
() {
user = ..(id);
(!user) {
();
}
user;
}
