module.exports = (err, req, res, next) => {
  const status = err.status || 500;
  const payload = {
    message: err.message || 'Beklenmeyen bir hata olustu',
    code: err.code || 'UNEXPECTED_ERROR'
  };

  if (process.env.NODE_ENV !== 'production' && err.stack) {
    payload.stack = err.stack;
  }

  res.status(status).json(payload);
};
