Skip to content

Commit f117e7d

Browse files
committed
Adding getters on AppsyncResponse to read the data or the error
1 parent 71ade42 commit f117e7d

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

lambda-appsync-proc/src/internal/make_appsync/make_handlers.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ impl ToTokens for MakeHandlers {
161161
event.info.operation.execute(event).instrument(
162162
::tracing::info_span!(
163163
"AppsyncEvent",
164-
"otel.name"=format!("AppsyncEvent"),
165164
?operation
166165
)
167166
).await

lambda-appsync/src/lib.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,34 @@ impl AppsyncResponse {
378378
pub fn unauthorized() -> Self {
379379
AppsyncError::new("Unauthorized", "This operation cannot be authorized").into()
380380
}
381+
382+
/// Returns a reference to the response data, if present
383+
///
384+
/// # Examples
385+
///
386+
/// ```
387+
/// # use lambda_appsync::AppsyncResponse;
388+
/// # use serde_json::json;
389+
/// let response = AppsyncResponse::from(json!({"user": "Alice"}));
390+
/// assert!(response.data().is_some());
391+
/// ```
392+
pub fn data(&self) -> Option<&Value> {
393+
self.data.as_ref()
394+
}
395+
396+
/// Returns a reference to the response error, if present
397+
///
398+
/// # Examples
399+
///
400+
/// ```
401+
/// # use lambda_appsync::{AppsyncResponse, AppsyncError};
402+
/// let error = AppsyncError::new("NotFound", "User not found");
403+
/// let response = AppsyncResponse::from(error);
404+
/// assert!(response.error().is_some());
405+
/// ```
406+
pub fn error(&self) -> Option<&AppsyncError> {
407+
self.error.as_ref()
408+
}
381409
}
382410

383411
impl From<Value> for AppsyncResponse {

0 commit comments

Comments
 (0)