#[derive(Debug)]
enum CanvasError {
NotExists,
- DimensionMismatch,
+ DimensionMismatch((u32, u32)),
ImageError(ImageError)
}
fn status_code(&self) -> StatusCode {
match &self {
CanvasError::NotExists => StatusCode::NOT_FOUND,
- CanvasError::DimensionMismatch => StatusCode::BAD_REQUEST,
+ CanvasError::DimensionMismatch(_) => StatusCode::BAD_REQUEST,
CanvasError::ImageError(e) => e.status_code()
}
}
fn error_response(&self) -> HttpResponse<BoxBody> {
match &self {
CanvasError::NotExists => HttpResponse::NotFound().body("Canvas does not exist."),
- CanvasError::DimensionMismatch => HttpResponse::BadRequest().body("Supplied dimensions don't much the dimensions of existing canvas."),
+ CanvasError::DimensionMismatch(dim) =>
+ HttpResponse::BadRequest().body(format!("Supplied dimensions don't match the dimensions of existing canvas {:?}.", dim)),
CanvasError::ImageError(e) => e.error_response()
}
}
Ok(canvas)
}
else {
- _ = canvas_option.insert(canvas);
- Err(CanvasError::DimensionMismatch)
+ Err(CanvasError::DimensionMismatch(canvas_option.insert(canvas).img.dimensions()))
}
},
None =>