You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 27ea71c
Browse filesBrowse the repository at this point in the historyBrowse files
Apply a mounting API's default_error_status to routes defined before the mount (#3083)
Each route's settings were forked with `default_error_status ||= 500`,
which wrote 500 into the route's own copy whenever nothing above it had
set a status yet. An API whose routes were defined before it was mounted,
the usual layout, so kept answering 500 from `error!` and from exceptions
`rescue_from` answered without a status, even under an API that set
`default_error_status`. The 500 now applies where the status is read, so
the mounting API's value reaches those routes, as its `format` and
`rescue_from` already did, and a mounted API's own value still wins.
Replaces #1264. Fixes#1177.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,6 +44,7 @@
44
44
*[#3079](https://github.com/ruby-grape/grape/pull/3079): Fix two dead links in the README - [@farisbasha](https://github.com/farisbasha).
45
45
*[#3080](https://github.com/ruby-grape/grape/pull/3080): Drop the `active_support/isolated_execution_state` require that ActiveSupport now autoloads - [@ericproulx](https://github.com/ericproulx).
46
46
*[#3082](https://github.com/ruby-grape/grape/pull/3082): Stop reporting the keys of a param its validators rejected as undeclared - [@ericproulx](https://github.com/ericproulx).
47
+
*[#3083](https://github.com/ruby-grape/grape/pull/3083): Apply a mounting API's `default_error_status` to routes defined before the mount - [@ericproulx](https://github.com/ericproulx).
Copy file name to clipboardExpand all lines: UPGRADING.md
+19Lines changed: 19 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -113,6 +113,25 @@ end
113
113
114
114
To keep the enclosing handler for such an exception, register its class in the nested scope as well: a scope's class handlers still rank ahead of its own `rescue_from :all`. An exception `rescue_from :all` does not catch, one that is not a `StandardError`, still reaches the enclosing scope's handlers, and so does one raised inside the catch-all's block.
115
115
116
+
#### A mounting API's `default_error_status` reaches the routes its mounted APIs defined first
117
+
118
+
An API's `default_error_status` now applies to every route of the APIs it mounts, whichever was defined first ([#3083](https://github.com/ruby-grape/grape/pull/3083)). A route used to keep 500 when nothing above it had set `default_error_status` by the time it was defined. So in the usual layout below, where the mounted API is defined before the API that mounts it, `error!` and the exceptions `rescue_from` answers without a status of their own gave 500:
119
+
120
+
```ruby
121
+
classStatus < Grape::API
122
+
get :statusdo
123
+
error!('unavailable') # now 400, was 500
124
+
end
125
+
end
126
+
127
+
classBase < Grape::API
128
+
default_error_status 400
129
+
mount Status
130
+
end
131
+
```
132
+
133
+
A route defined after the mount already answered 400. A `default_error_status` the mounting API sets after `mount` now applies too, as its `format` and `rescue_from` already did. A mounted API's own `default_error_status` still wins, so to keep 500 in a mounted API, declare `default_error_status 500` in it.
134
+
116
135
### Upgrading to >= 4.1.0
117
136
118
137
#### `Rack::Head` wraps the router instead of each endpoint's stack
0 commit comments