aboutsummaryrefslogtreecommitdiff
path: root/brep/module.cxx
blob: 31e5f999feb745764f9933849a76f3c4d8ae65f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// file      : brep/module.cxx -*- C++ -*-
// copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC
// license   : MIT; see accompanying LICENSE file

#include <brep/module>

#include <functional> // bind()

using namespace std;

namespace brep
{

  void module::
  handle (request& rq, response& rs, log& l)
  {
    log_ = &l;

    try
    {
      handle (rq, rs);
    }
    catch (const invalid_request& e)
    {
      // @@ Both log and format as HTML in proper style, etc.
      //
      rs.content (e.status, "text/html;charset=utf-8") << e.description;
    }
    catch (const server_error& e)
    {
      // @@ Both log and return as 505.
      //
      write (move (e.data));
    }
    catch (const exception& e)
    {
      // @@ Exception: log e.what () & 505.
      //
      rs.status (505);
    }
    catch (...)
    {
      // @@ Unknown exception: log & 505.
      //
      rs.status (505);
    }
  }

  module::
  module ()
      : error (severity::error, log_writer_),
        warn (severity::warn, log_writer_),
        info (severity::info, log_writer_),
        log_writer_ (bind (&module::write, this, _1))
  {
  }

  void module::
  log_write (diag_data&& d) const
  {
    if (log_ == nullptr)
      return; // No backend yet.

    //@@ Cast log_ to apache::log and write the records.
    //
  }
}