Process request function now handles errors