## Class error_handler

zeep::http::error_handler — A base class for error-handler classes.

## Synopsis

    // In header: <zeep/http/error-handler.hpp>

    class error_handler {
    public:
      // construct/copy/destruct
      error_handler(const std::string & = "error.xhtml");
      error_handler(const error_handler &) = delete;
      error_handler & operator=(const error_handler &) = delete;
      ~error_handler();

      // public member functions
      void set_server(basic_server *);
      basic_server * get_server();
      const basic_server * get_server() const;
      virtual bool
      create_error_reply(const request &, std::exception_ptr, reply &);
      virtual bool create_unauth_reply(const request &, reply &);
      virtual bool create_error_reply(const request &, status_type, reply &);
      virtual bool
      create_error_reply(const request &, status_type, const std::string &,
                         reply &);
    };

## Description

To handle errors decently when there are multiple controllers.

### `error_handler` public construct/copy/destruct

1.     error_handler(const std::string & error_template = "error.xhtml");

   constructor

   If error_template is not empty, the error handler will try to load this XHTML template using the server's template_processor. If that fails or error_template is empty, a simple stock message is returned.

2.     error_handler(const error_handler &) = delete;

3.     error_handler & operator=(const error_handler &) = delete;

4.     ~error_handler();

### `error_handler` public member functions

1.     void set_server(basic_server * s);

   set the server object we're bound to

2.     basic_server * get_server();

   get the server object we're bound to

3.     const basic_server * get_server() const;

   set the server object we're bound to

4.     virtual bool
       create_error_reply(const request & req, std::exception_ptr eptr,
                          reply & reply);

   Create an error reply for an exception.

   This function is called by server with the captured exception.

   Parameters:

   `eptr` | The captured exception, use std::rethrow_exception to use this
   `reply` | Write the reply in this object
   `req` | The request that triggered this call

   Returns: | Return true if the reply was created successfully

5.     virtual bool create_unauth_reply(const request & req, reply & reply);

   Create an error reply for the error containing a validation header.

   When a authentication violation is encountered, this function is called to generate the appropriate reply.

   Parameters:

   `reply` | Write the reply in this object
   `req` | The request that triggered this call

   Returns: | Return true if the reply was created successfully

6.     virtual bool
       create_error_reply(const request & req, status_type status, reply & reply);

   Create an error reply for the error.

   An error should be returned with HTTP status code status. This method will create a default error page.

   Parameters:

   `reply` | Write the reply in this object
   `req` | The request that triggered this call
   `status` | The status code, describing the error

   Returns: | Return true if the reply was created successfully

7.     virtual bool
       create_error_reply(const request & req, status_type status,
                          const std::string & message, reply & reply);

   Create an error reply for the error with an additional message for the user.

   An error should be returned with HTTP status code status and additional information message. This method will create a default error page.

   Parameters:

   `message` | The message describing the error
   `reply` | Write the reply in this object
   `req` | The request that triggered this call
   `status` | The error that triggered this call

   Returns: | Return true if the reply was created successfully