This repository has been archived by the owner on Jun 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Track response in error details #29
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d15f64e
feat: Track response in error details
tomasfarias 784878e
fix: Remove useless format
tomasfarias 9bb7324
read first n bytes of error response
bretthoerner cc05f55
refactor: Read chunks until n bytes instead of take
tomasfarias 6743384
refactor: Error instead of breaking
tomasfarias 823e3d0
fix: Extra whitespace in Cargo.toml
tomasfarias bf72a0c
fix: Typo
tomasfarias 1aa8913
fix: Remove inaccurate comment
tomasfarias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod config; | ||
pub mod error; | ||
pub mod util; | ||
pub mod worker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use crate::error::WebhookResponseError; | ||
use futures::StreamExt; | ||
use reqwest::Response; | ||
|
||
pub async fn first_n_bytes_of_response( | ||
response: Response, | ||
n: usize, | ||
) -> Result<String, WebhookResponseError> { | ||
let mut body = response.bytes_stream(); | ||
let mut buffer = String::with_capacity(n); | ||
|
||
while let Some(chunk) = body.next().await { | ||
if buffer.len() >= n { | ||
break; | ||
} | ||
|
||
let chunk = chunk?; | ||
let chunk_str = std::str::from_utf8(&chunk)?; | ||
let upper_bound = std::cmp::min(n - buffer.len(), chunk_str.len()); | ||
|
||
if let Some(partial_chunk_str) = chunk_str.get(0..upper_bound) { | ||
buffer.push_str(partial_chunk_str); | ||
} else { | ||
// For whatever reason we are out of bounds. We should never land here | ||
// given the `std::cmp::min` usage, but I am being extra careful by not | ||
// using a slice index that would panic instead. | ||
return Err(WebhookResponseError::ChunkOutOfBoundsError( | ||
chunk_str.len(), | ||
upper_bound, | ||
)); | ||
} | ||
} | ||
|
||
Ok(buffer) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not handling these at the moment.
hook-worker
just defaults to an empty response on error.