Skip to content

Commit ecb2f97

Browse files
committed
Do not log Not Found errors
1 parent bae2f2a commit ecb2f97

3 files changed

Lines changed: 8 additions & 7 deletions

File tree

TODO.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
## Immediate
22

3-
- [ ] On internal error in module, default response should be to display page
4-
showing error, with auto refresh on file change
5-
- [ ] Do not log error backtrace for 404 errors (or other )
63
- [ ] Collection - treat directories and files as collections of data.
74

85
Kind of similar to the routing tree, but instead of routes it just takes a

lib/syntropy/app.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def call(req)
7676
method: req.method,
7777
path: req.path,
7878
error: e
79-
)
79+
) if Error.log_error?(e)
8080
error_handler = get_error_handler(route)
8181
error_handler.(req, e)
8282
end

lib/syntropy/errors.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Error < StandardError
88
Status = Qeweney::Status
99

1010
# By default, the HTTP status for errors is 500 Internal Server Error
11-
DEFAULT_STATUS = Qeweney::Status::INTERNAL_SERVER_ERROR
11+
DEFAULT_STATUS = Status::INTERNAL_SERVER_ERROR
1212

1313
# Returns the HTTP status for the given exception
1414
#
@@ -18,6 +18,10 @@ def self.http_status(err)
1818
err.respond_to?(:http_status) ? err.http_status : DEFAULT_STATUS
1919
end
2020

21+
def self.log_error?(err)
22+
http_status(err) != Status::NOT_FOUND
23+
end
24+
2125
# Creates an error with status 404 Not Found
2226
#
2327
# @return [Syntropy::Error]
@@ -49,14 +53,14 @@ def initialize(msg = 'Internal server error', http_status = DEFAULT_STATUS)
4953
#
5054
# @return [Integer, String] HTTP status
5155
def http_status
52-
@http_status || Qeweney::Status::INTERNAL_SERVER_ERROR
56+
@http_status || Status::INTERNAL_SERVER_ERROR
5357
end
5458
end
5559

5660
# ValidationError is raised when a validation has failed.
5761
class ValidationError < Error
5862
def initialize(msg)
59-
super(msg, Qeweney::Status::BAD_REQUEST)
63+
super(msg, Status::BAD_REQUEST)
6064
end
6165
end
6266
end

0 commit comments

Comments
 (0)