lennarb 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0e10a539894e1cf41bcebf4c01b086092d36779b1b8aebada8eabc717552348
4
- data.tar.gz: 86afa28d62c0b532e08027df8a1847bc4a72b36347388b11f4c6f7aef8c2d345
3
+ metadata.gz: 4f3ac7cfbc2516f8bae7fd4e5d9fdbab7b02fc8c8545423bc434f7462e7e11b2
4
+ data.tar.gz: 00ada2a17115680425bc16d478f22419e769944b2919d5d2ab5ad266884aba94
5
5
  SHA512:
6
- metadata.gz: '0539b0de41e1de79c84a89204c67931dcf0b015a2401db8bece03ef66e8fc5b7e74c87527bb431d1ec447998b067738bb41127f68917d0dbcfd44ff973294935'
7
- data.tar.gz: 88820bc3511a72fda57ef39fac259c69cc632dcb3ad0d9faa4b3514327603cc78cd6e5b6531b4c632a109901883e5ca642fa13904ab8e6445cecea466edde298
6
+ metadata.gz: bbdef1cf8b5415106566aaa73dfe94ea99e56f5fe4bb808f57742bcf0d2e575952b1b4cb6cdbd0edcce102fbb8d6b9ec386ec7f60aa4d29e0edcce699f3950e7
7
+ data.tar.gz: 75f1097c8a992d9256f8faf3d5a967d9e7ab1926703e7228b87a75bc95d119ba1d52281726d8d6e8bd5e62ebf0bf693d5c9dab2de3cc4cb64f68e0a30024daa0
data/CHANGELOG.md CHANGED
@@ -4,14 +4,28 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
- ## [Released]
7
+ ## [0.1.2] - 2023-23-11
8
+
9
+ ### Added
10
+
11
+ - Implemented a specific error handler for Content-Type related errors, enhancing the system's ability to respond appropriately based on whether the request Content-Type is JSON or HTML.
12
+
13
+ ### Removed
14
+
15
+ - Removed the debug gem from development dependencies, streamlining the development environment setup.
16
+
17
+ ### Fixed
18
+
19
+ - Fixed a bug that prevented the correct reading of the Content-Type header in requests, ensuring proper handling of content types.
8
20
 
9
21
  ## [0.1.1] - 2023-23-11
10
22
 
11
23
  ### Added
24
+
12
25
  - Introduced `Array.wrap` extension to the `Array` class for more reliable conversion of objects to arrays within the Lennarb router environment. This method ensures consistent array wrapping of single objects and `nil` values.
13
26
 
14
27
  ### Changed
28
+
15
29
  - Refactored the `put_header` method to use the `Array.wrap` method for more predictable header value handling.
16
30
  - Renamed methods to have a consistent `assign_` prefix to standardize the API interface:
17
31
  - `put_header` to `assign_header`
@@ -24,7 +24,7 @@ module Lenna
24
24
  env = req.env
25
25
  log_error(env, e)
26
26
 
27
- render_error_page(e, env, res)
27
+ render_error_page(e, env, req, res)
28
28
  end
29
29
 
30
30
  private
@@ -37,10 +37,43 @@ module Lenna
37
37
  # @return [void]
38
38
  #
39
39
  # @api private
40
- def render_error_page(error, env, res)
41
- res.put_status(500)
42
- res.put_header('Content-Type', 'text/html')
43
- res.put_body(error_page(error, env))
40
+ def render_error_page(error, env, req, res)
41
+ case req.headers['Content-Type']
42
+ in 'application/json' then render_json(error, env, res)
43
+ else render_html(error, env, res)
44
+ end
45
+ end
46
+
47
+ # This method will render the JSON error page.
48
+ #
49
+ # @param error [StandardError] The error object
50
+ # @param env [Hash] The environment variables
51
+ # @param res [Rack::Response] The response object
52
+ # @return [void]
53
+ #
54
+ # @api private
55
+ def render_json(error, env, res)
56
+ case env['RACK_ENV']
57
+ in 'development' | 'test' then res.json(
58
+ data: {
59
+ error: error.message,
60
+ status: 500
61
+ }
62
+ )
63
+ else res.json(error: 'Internal Server Error', status: 500)
64
+ end
65
+ end
66
+
67
+ # This method will render the HTML error page.
68
+ #
69
+ # @param error [StandardError] The error object
70
+ # @param env [Hash] The environment variables
71
+ # @param res [Rack::Response] The response object
72
+ # @return [void]
73
+ #
74
+ # @api private
75
+ def render_html(error, env, res)
76
+ res.html(error_page(error, env), status: 500)
44
77
  end
45
78
 
46
79
  # This method will log the error.
@@ -37,8 +37,12 @@ module Lenna
37
37
  # Turn this:
38
38
  # HTTP_FOO=bar Foo=bar
39
39
  def headers
40
+ content_type = env['CONTENT_TYPE']
40
41
  @headers ||= env.select { |k, _| k.start_with?('HTTP_') }
41
42
  .transform_keys { |k| format_header_name(k) }
43
+
44
+ @headers['Content-Type'] = content_type if content_type
45
+ @headers
42
46
  end
43
47
 
44
48
  # This method returns the request body in a normalized way.
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lennarb
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.3'
5
5
 
6
6
  public_constant :VERSION
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lennarb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aristóteles Coutinho
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-21 00:00:00.000000000 Z
11
+ date: 2023-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize