@@ -81,13 +81,13 @@ where
81
81
let param_1_as_object = match param_1. map ( |value| {
82
82
value. as_object ( ) . ok_or_else ( || {
83
83
handlebars:: RenderError :: new ( format ! (
84
- "Custom context provided to the `get` helper must be an object, but it was `{}`." ,
85
- value,
84
+ "Custom context provided to `get \" {} \" ` must be an object, but it was `{}`." ,
85
+ route , value,
86
86
) )
87
87
} )
88
88
} ) {
89
89
Some ( Ok ( object) ) => Some ( object) ,
90
- Some ( Err ( error) ) => { return Err ( error) } ,
90
+ Some ( Err ( error) ) => return Err ( error) ,
91
91
None => None ,
92
92
} ;
93
93
@@ -109,15 +109,13 @@ where
109
109
} ) ;
110
110
111
111
let content_item = content_engine. get_internal ( & route) . ok_or_else ( || {
112
- handlebars:: RenderError :: new ( format ! (
113
- "No content found at route passed to `get` helper (\" {}\" )." ,
114
- route,
115
- ) )
112
+ handlebars:: RenderError :: new ( format ! ( "No content found for `get \" {}\" `." , route) )
116
113
} ) ?;
117
114
118
115
let current_render_data = handlebars_context. data ( ) . as_object ( ) . ok_or_else ( || {
119
116
handlebars:: RenderError :: new ( format ! (
120
- "The `get` helper call failed because the context JSON was not an object. It is `{}`." ,
117
+ "The `get \" {}\" ` helper call failed because the immediate render data was not an object (it was `{}`)." ,
118
+ route,
121
119
handlebars_context. data( ) ,
122
120
) )
123
121
} ) ?;
@@ -130,8 +128,9 @@ where
130
128
serde_json:: Value :: Object ( modified_context_data_as_json_map) => modified_context_data_as_json_map,
131
129
_ => {
132
130
return Err ( handlebars:: RenderError :: new ( format ! (
133
- "The `get` helper call failed because the pre-existing handlebars render context was \
131
+ "The `get \" {} \" ` helper call failed because the pre-existing handlebars render context was \
134
132
not an object (it was `{}`).",
133
+ route,
135
134
modified_context_data_as_json
136
135
) ) )
137
136
}
@@ -151,22 +150,21 @@ where
151
150
serde_json:: Value :: Object ( modified_context_data_as_json_map) ,
152
151
) ) ;
153
152
154
- let target_media_type = get_target_media_type ( current_render_data) ?;
155
- let optional_request_route = get_optional_request_route ( current_render_data) ?;
156
- let query_parameters = get_query_parameters ( current_render_data) ?;
157
- let request_headers = get_request_headers ( current_render_data) ?;
153
+ let target_media_type = get_target_media_type ( current_render_data, & route ) ?;
154
+ let optional_request_route = get_optional_request_route ( current_render_data, & route ) ?;
155
+ let query_parameters = get_query_parameters ( current_render_data, & route ) ?;
156
+ let request_headers = get_request_headers ( current_render_data, & route ) ?;
158
157
159
158
let context = content_engine
160
159
. render_context ( optional_request_route, query_parameters, request_headers)
161
160
. with_handlebars_render_context ( handlebars_render_context. clone ( ) ) ;
162
161
163
162
let rendered = content_item
164
- . render ( context, & [ target_media_type. into_media_range ( ) ] ) . map_err ( |render_error| {
163
+ . render ( context, & [ target_media_type. into_media_range ( ) ] )
164
+ . map_err ( |render_error| {
165
165
handlebars:: RenderError :: new ( format ! (
166
- "The `get` helper call failed because the content item being retrieved (\" {}\" ) \
167
- could not be rendered: {}",
168
- route,
169
- render_error,
166
+ "The `get \" {}\" ` helper call failed because {} could not be rendered: {}" ,
167
+ route, route, render_error,
170
168
) )
171
169
} ) ?;
172
170
@@ -182,8 +180,9 @@ where
182
180
) )
183
181
. map_err ( |streaming_error| {
184
182
handlebars:: RenderError :: new ( format ! (
185
- "The `get` helper call failed because there was an error collecting the rendered content \
186
- for \" {}\" : {}",
183
+ "The `get \" {}\" ` helper call failed because there was an error collecting the rendered content \
184
+ for {}: {}",
185
+ route,
187
186
route,
188
187
streaming_error,
189
188
) )
@@ -197,16 +196,18 @@ where
197
196
198
197
fn get_target_media_type (
199
198
render_data : & serde_json:: value:: Map < String , serde_json:: Value > ,
199
+ route : & Route ,
200
200
) -> Result < MediaType , handlebars:: RenderError > {
201
201
let target_media_type = render_data
202
202
. get ( TARGET_MEDIA_TYPE_PROPERTY_NAME )
203
203
. and_then ( |value| value. as_str ( ) )
204
204
. and_then ( |media_type_essence| media_type_essence. parse :: < MediaType > ( ) . ok ( ) )
205
205
. ok_or_else ( || {
206
206
handlebars:: RenderError :: new ( format ! (
207
- "The `get` helper call failed because a valid target media type could not be found \
208
- in the handlebars context. The context JSON must contain a property at `{}` \
209
- whose value is a valid media type essence string.",
207
+ "The `get \" {}\" ` helper call failed because a valid target media type could not be found \
208
+ in the handlebars context. The context JSON must contain a property at `{}` whose value is \
209
+ a valid media type essence string.",
210
+ route,
210
211
TARGET_MEDIA_TYPE_PROPERTY_NAME ,
211
212
) )
212
213
} ) ?;
@@ -215,16 +216,18 @@ fn get_target_media_type(
215
216
216
217
fn get_optional_request_route (
217
218
render_data : & serde_json:: value:: Map < String , serde_json:: Value > ,
219
+ route : & Route ,
218
220
) -> Result < Option < Route > , handlebars:: RenderError > {
219
221
let optional_request_route = {
220
222
let request_route_value = render_data
221
223
. get ( REQUEST_DATA_PROPERTY_NAME )
222
224
. and_then ( |request_data| request_data. get ( ROUTE_PROPERTY_NAME ) )
223
225
. ok_or_else ( || {
224
226
handlebars:: RenderError :: new ( format ! (
225
- "The `get` helper call failed because the request route could not be found \
226
- in the handlebars context. The context JSON must contain a property at `{}.{}` \
227
- whose value is a string or null.",
227
+ "The `get \" {}\" ` helper call failed because the request route could not be found in the \
228
+ handlebars context. The context JSON must contain a property at `{}.{}` whose value is a \
229
+ string or null.",
230
+ route,
228
231
REQUEST_DATA_PROPERTY_NAME , ROUTE_PROPERTY_NAME
229
232
) )
230
233
} ) ?;
@@ -235,15 +238,18 @@ fn get_optional_request_route(
235
238
let request_route = request_route_value. as_str ( )
236
239
. ok_or_else ( || {
237
240
handlebars:: RenderError :: new ( format ! (
238
- "The `get` helper call failed because the request route in the handlebars context was \
241
+ "The `get \" {} \" ` helper call failed because the request route in the handlebars context was \
239
242
not a string or null (it was `{}`).",
243
+ route,
240
244
request_route_value,
241
245
) )
242
246
} ) ?
243
247
. parse :: < Route > ( )
244
248
. map_err ( |error| {
245
249
handlebars:: RenderError :: new ( format ! (
246
- "The `get` helper call failed because the request route in the handlebars context was invalid ({})." ,
250
+ "The `get \" {}\" ` helper call failed because the request route in the handlebars context was \
251
+ invalid ({}).",
252
+ route,
247
253
error,
248
254
) )
249
255
} ) ?;
@@ -255,24 +261,26 @@ fn get_optional_request_route(
255
261
256
262
fn get_query_parameters (
257
263
render_data : & serde_json:: value:: Map < String , serde_json:: Value > ,
264
+ route : & Route ,
258
265
) -> Result < HashMap < String , String > , handlebars:: RenderError > {
259
266
let query_parameters = render_data
260
267
. get ( REQUEST_DATA_PROPERTY_NAME )
261
268
. and_then ( |request_data| request_data. get ( QUERY_PARAMETERS_PROPERTY_NAME ) )
262
269
. ok_or_else ( || {
263
270
handlebars:: RenderError :: new ( format ! (
264
- "The `get` helper call failed because the query parameters could not be found \
265
- in the handlebars context. The context JSON must contain a property at `{}.{}` \
266
- whose value is a map." ,
271
+ "The `get \" {} \" ` helper call failed because the query parameters could not be found in the \
272
+ handlebars context. The context JSON must contain a property at `{}.{}` whose value is a map." ,
273
+ route ,
267
274
REQUEST_DATA_PROPERTY_NAME ,
268
275
QUERY_PARAMETERS_PROPERTY_NAME ,
269
276
) )
270
277
} ) ?
271
278
. as_object ( )
272
279
. ok_or_else ( || {
273
- handlebars:: RenderError :: new ( String :: from (
274
- "The `get` helper call failed because the query parameters in the handlebars context \
275
- was not a map."
280
+ handlebars:: RenderError :: new ( format ! (
281
+ "The `get \" {}\" ` helper call failed because the query parameters in the handlebars context \
282
+ was not a map.",
283
+ route,
276
284
) )
277
285
} ) ?
278
286
. into_iter ( )
@@ -287,22 +295,25 @@ fn get_query_parameters(
287
295
288
296
fn get_request_headers (
289
297
render_data : & serde_json:: value:: Map < String , serde_json:: Value > ,
298
+ route : & Route ,
290
299
) -> Result < HashMap < String , String > , handlebars:: RenderError > {
291
300
let request_headers = render_data
292
301
. get ( REQUEST_DATA_PROPERTY_NAME )
293
302
. and_then ( |request_data| request_data. get ( REQUEST_HEADERS_PROPERTY_NAME ) )
294
303
. ok_or_else ( || {
295
304
handlebars:: RenderError :: new ( format ! (
296
- "The `get` helper call failed because the request headers could not be found \
297
- in the handlebars context. The context JSON must contain a property at `{}.{}` \
298
- whose value is a map.",
305
+ "The `get \" {}\" ` helper call failed because the request headers could not be found in \
306
+ the handlebars context. The context JSON must contain a property at `{}.{}` whose value \
307
+ is a map.",
308
+ route,
299
309
REQUEST_DATA_PROPERTY_NAME ,
300
310
REQUEST_HEADERS_PROPERTY_NAME
301
311
) )
302
312
} ) ?. as_object ( ) . ok_or_else ( || {
303
- handlebars:: RenderError :: new ( String :: from (
304
- "The `get` helper call failed because the request headers in the handlebars context \
305
- was not a map."
313
+ handlebars:: RenderError :: new ( format ! (
314
+ "The `get \" {}\" ` helper call failed because the request headers in the handlebars context \
315
+ was not a map.",
316
+ route,
306
317
) )
307
318
} ) ?
308
319
. into_iter ( )
0 commit comments