Skip to content

Commit

Permalink
Replace RemoteOperationFailed with S3-specific sub-errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
emmiegit committed Oct 16, 2023
1 parent 6d86fb8 commit ceb7201
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
13 changes: 6 additions & 7 deletions deepwell/src/services/blob/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl BlobService {
tide::log::debug!("Blob with hash {hex_hash} already exists");

// Content-Type header should be passed in
let mime = result.content_type.ok_or(Error::RemoteOperationFailed)?;
let mime = result.content_type.ok_or(Error::S3Response)?;

Ok(CreateBlobOutput {
hash,
Expand Down Expand Up @@ -168,14 +168,13 @@ impl BlobService {
None => Ok(None),
Some(result) => {
// Headers should be passed in
let size = result.content_length.ok_or(Error::RemoteOperationFailed)?;
let mime = result.content_type.ok_or(Error::RemoteOperationFailed)?;
let size = result.content_length.ok_or(Error::S3Response)?;
let mime = result.content_type.ok_or(Error::S3Response)?;
let created_at = {
let timestamp =
result.last_modified.ok_or(Error::RemoteOperationFailed)?;
let timestamp = result.last_modified.ok_or(Error::S3Response)?;

OffsetDateTime::parse(&timestamp, &Rfc2822)
.map_err(|_| Error::RemoteOperationFailed)?
.map_err(|_| Error::S3Response)?
};

Ok(Some(BlobMetadata {
Expand Down Expand Up @@ -279,5 +278,5 @@ fn s3_error<T>(response: &ResponseData, action: &str) -> Result<T> {
);

// TODO replace with S3 backend-specific error
Err(Error::RemoteOperationFailed)
Err(Error::S3Response)
}
23 changes: 11 additions & 12 deletions deepwell/src/services/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,21 @@ pub enum Error {
#[error("Serialization error: {0}")]
Serde(#[from] serde_json::Error),

#[error("S3 error: {0}")]
S3(#[from] S3Error),
#[error("S3 service returned error: {0}")]
S3Service(#[from] S3Error),

#[error("S3 service failed to respond properly")]
S3Response,

#[error("Email verification error: {}", .0.as_ref().unwrap_or(&str!("<unspecified>")))]
EmailVerification(Option<String>),

// See also RemoteOperationFailed.
#[error("Web request error: {0}")]
WebRequest(#[from] ReqwestError),

#[error("Invalid enum serialization value")]
InvalidEnumValue,

#[error("A request to a remote service returned an error")]
RemoteOperationFailed,

#[error("Attempting to perform a wikitext parse and render has timed out")]
RenderTimeout,

Expand Down Expand Up @@ -166,15 +165,15 @@ impl Error {
Error::Conflict => 2002,

// 3000 - Server errors, unexpected
Error::RemoteOperationFailed => 3000,
Error::RateLimited => 3001,
Error::WebRequest(_) => 3002,
Error::AuthenticationBackend(_) => 3003,
Error::RateLimited => 3000,
Error::WebRequest(_) => 3001,
Error::AuthenticationBackend(_) => 3002,

// 3100 -- Remote services
Error::RenderTimeout => 3100,
Error::S3(_) => 3101,
Error::EmailVerification(_) => 3102,
Error::EmailVerification(_) => 3101,
Error::S3Service(_) => 3102,
Error::S3Response => 3103,

// 3200 -- Backend issues
Error::Serde(_) => 3200,
Expand Down

0 comments on commit ceb7201

Please sign in to comment.