Software /
code /
prosody
Annotate
net/http/errors.lua @ 13652:a08065207ef0
net.server_epoll: Call :shutdown() on TLS sockets when supported
Comment from Matthew:
This fixes a potential issue where the Prosody process gets blocked on sockets
waiting for them to close. Unlike non-TLS sockets, closing a TLS socket sends
layer 7 data, and this can cause problems for sockets which are in the process
of being cleaned up.
This depends on LuaSec changes which are not yet upstream.
From Martijn's original email:
So first my analysis of luasec. in ssl.c the socket is put into blocking
mode right before calling SSL_shutdown() inside meth_destroy(). My best
guess to why this is is because meth_destroy is linked to the __close
and __gc methods, which can't exactly be called multiple times and
luasec does want to make sure that a tls session is shutdown as clean
as possible.
I can't say I disagree with this reasoning and don't want to change this
behaviour. My solution to this without changing the current behaviour is
to introduce a shutdown() method. I am aware that this overlaps in a
conflicting way with tcp's shutdown method, but it stays close to the
OpenSSL name. This method calls SSL_shutdown() in the current
(non)blocking mode of the underlying socket and returns a boolean
whether or not the shutdown is completed (matching SSL_shutdown()'s 0
or 1 return values), and returns the familiar ssl_ioerror() strings on
error with a false for completion. This error can then be used to
determine if we have wantread/wantwrite to finalize things. Once
meth_shutdown() has been called once a shutdown flag will be set, which
indicates to meth_destroy() that the SSL_shutdown() has been handled
by the application and it shouldn't be needed to set the socket to
blocking mode. I've left the SSL_shutdown() call in the
LSEC_STATE_CONNECTED to prevent TOCTOU if the application reaches a
timeout for the shutdown code, which might allow SSL_shutdown() to
clean up anyway at the last possible moment.
Another thing I've changed to luasec is the call to socket_setblocking()
right before calling close(2) in socket_destroy() in usocket.c.
According to the latest POSIX[0]:
Note that the requirement for close() on a socket to block for up to
the current linger interval is not conditional on the O_NONBLOCK
setting.
Which I read to mean that removing O_NONBLOCK on the socket before close
doesn't impact the behaviour and only causes noise in system call
tracers. I didn't touch the windows bits of this, since I don't do
windows.
For the prosody side of things I've made the TLS shutdown bits resemble
interface:onwritable(), and put it under a combined guard of self._tls
and self.conn.shutdown. The self._tls bit is there to prevent getting
stuck on this condition, and self.conn.shutdown is there to prevent the
code being called by instances where the patched luasec isn't deployed.
The destroy() method can be called from various places and is read by
me as the "we give up" error path. To accommodate for these unexpected
entrypoints I've added a single call to self.conn:shutdown() to prevent
the socket being put into blocking mode. I have no expectations that
there is any other use here. Same as previous, the self.conn.shutdown
check is there to make sure it's not called on unpatched luasec
deployments and self._tls is there to make sure we don't call shutdown()
on tcp sockets.
I wouldn't recommend logging of the conn:shutdown() error inside
close(), since a lot of clients simply close the connection before
SSL_shutdown() is done.
author | Martijn van Duren <martijn@openbsd.org> |
---|---|
date | Thu, 06 Feb 2025 15:04:38 +0000 |
parent | 12974:ba409c67353b |
rev | line source |
---|---|
11025
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 -- This module returns a table that is suitable for use as a util.error registry, |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 -- and a function to return a util.error object given callback 'code' and 'body' |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 -- parameters. |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 |
12974
ba409c67353b
net: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
11225
diff
changeset
|
5 local codes = require "prosody.net.http.codes"; |
ba409c67353b
net: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
11225
diff
changeset
|
6 local util_error = require "prosody.util.error"; |
11025
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 local error_templates = { |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 -- This code is used by us to report a client-side or connection error. |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 -- Instead of using the code, use the supplied body text to get one of |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 -- the more detailed errors below. |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 [0] = { |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 code = 0, type = "cancel", condition = "internal-server-error"; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 text = "Connection or internal error"; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 -- These are net.http built-in errors, they are returned in |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 -- the body parameter when code == 0 |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 ["cancelled"] = { |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 code = 0, type = "cancel", condition = "remote-server-timeout"; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 text = "Request cancelled"; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 ["connection-closed"] = { |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 code = 0, type = "wait", condition = "remote-server-timeout"; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 text = "Connection closed"; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 ["certificate-chain-invalid"] = { |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 code = 0, type = "cancel", condition = "remote-server-timeout"; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 text = "Server certificate not trusted"; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 ["certificate-verify-failed"] = { |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 code = 0, type = "cancel", condition = "remote-server-timeout"; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 text = "Server certificate invalid"; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 ["connection failed"] = { |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 code = 0, type = "cancel", condition = "remote-server-not-found"; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 text = "Connection failed"; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 ["invalid-url"] = { |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 code = 0, type = "modify", condition = "bad-request"; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 text = "Invalid URL"; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 }; |
11225
8c17c08d100e
net.http.errors: Add error class for DNS resolution failures (thanks SouL)
Matthew Wild <mwild1@gmail.com>
parents:
11025
diff
changeset
|
43 ["unable to resolve service"] = { |
8c17c08d100e
net.http.errors: Add error class for DNS resolution failures (thanks SouL)
Matthew Wild <mwild1@gmail.com>
parents:
11025
diff
changeset
|
44 code = 0, type = "cancel", condition = "remote-server-not-found"; |
8c17c08d100e
net.http.errors: Add error class for DNS resolution failures (thanks SouL)
Matthew Wild <mwild1@gmail.com>
parents:
11025
diff
changeset
|
45 text = "DNS resolution failed"; |
8c17c08d100e
net.http.errors: Add error class for DNS resolution failures (thanks SouL)
Matthew Wild <mwild1@gmail.com>
parents:
11025
diff
changeset
|
46 }; |
11025
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 -- This doesn't attempt to map every single HTTP code (not all have sane mappings), |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 -- but all the common ones should be covered. XEP-0086 was used as reference for |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 -- most of these. |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 [400] = { type = "modify", condition = "bad-request" }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 [401] = { type = "auth", condition = "not-authorized" }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 [402] = { type = "auth", condition = "payment-required" }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 [403] = { type = "auth", condition = "forbidden" }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 [404] = { type = "cancel", condition = "item-not-found" }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 [405] = { type = "cancel", condition = "not-allowed" }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 [406] = { type = "modify", condition = "not-acceptable" }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 [407] = { type = "auth", condition = "registration-required" }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 [408] = { type = "wait", condition = "remote-server-timeout" }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 [409] = { type = "cancel", condition = "conflict" }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 [410] = { type = "cancel", condition = "gone" }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 [411] = { type = "modify", condition = "bad-request" }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 [412] = { type = "cancel", condition = "conflict" }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 [413] = { type = "modify", condition = "resource-constraint" }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 [414] = { type = "modify", condition = "resource-constraint" }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 [415] = { type = "cancel", condition = "feature-not-implemented" }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 [416] = { type = "modify", condition = "bad-request" }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 [422] = { type = "modify", condition = "bad-request" }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 [423] = { type = "wait", condition = "resource-constraint" }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 [429] = { type = "wait", condition = "resource-constraint" }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 [431] = { type = "modify", condition = "resource-constraint" }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 [451] = { type = "auth", condition = "forbidden" }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 [500] = { type = "wait", condition = "internal-server-error" }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 [501] = { type = "cancel", condition = "feature-not-implemented" }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 [502] = { type = "wait", condition = "remote-server-timeout" }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 [503] = { type = "cancel", condition = "service-unavailable" }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 [504] = { type = "wait", condition = "remote-server-timeout" }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 [507] = { type = "wait", condition = "resource-constraint" }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 [511] = { type = "auth", condition = "not-authorized" }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 for k, v in pairs(codes) do |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 if error_templates[k] then |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 error_templates[k].code = k; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 error_templates[k].text = v; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 else |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 error_templates[k] = { type = "cancel", condition = "undefined-condition", text = v, code = k }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 end |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 end |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 setmetatable(error_templates, { |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 __index = function(_, k) |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 if type(k) ~= "number" then |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 return nil; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
98 end |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 return { |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 type = "cancel"; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 condition = "undefined-condition"; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 text = codes[k] or (k.." Unassigned"); |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 code = k; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 }; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 end |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 }); |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 local function new(code, body, context) |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 if code == 0 then |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 return util_error.new(body, context, error_templates); |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 else |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 return util_error.new(code, context, error_templates); |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 end |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 end |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 return { |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 registry = error_templates; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 new = new; |
e47e7185b403
net.http.errors: Add new module for converting net.http errors to util.error objects
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 }; |