mirror of https://github.com/realaravinth/gitpad
fix: add validation to check for empty file array during gist creation
parent
0ba7559425
commit
f5a22a2916
|
@ -69,6 +69,10 @@ async fn new(
|
|||
id: Identity,
|
||||
db: crate::DB,
|
||||
) -> ServiceResult<impl Responder> {
|
||||
if payload.files.is_empty() {
|
||||
return Err(ServiceError::GistEmpty);
|
||||
}
|
||||
|
||||
let username = id.identity().unwrap();
|
||||
let mut gist = data
|
||||
.new_gist(db.as_ref(), &payload.to_create_gist(&username))
|
||||
|
|
|
@ -191,6 +191,9 @@ impl Data {
|
|||
gist_id: GistID<'_>,
|
||||
files: &[FileInfo],
|
||||
) -> ServiceResult<()> {
|
||||
if files.is_empty() {
|
||||
return Err(ServiceError::GistEmpty);
|
||||
}
|
||||
// TODO change updated in DB
|
||||
let inner = |repo: &mut Repository| -> ServiceResult<()> {
|
||||
let mut tree_builder = repo.treebuilder(None).unwrap();
|
||||
|
|
|
@ -128,6 +128,12 @@ pub enum ServiceError {
|
|||
|
||||
#[display(fmt = "Unauthorized {}", _0)]
|
||||
UnauthorizedOperation(#[error(not(source))] String),
|
||||
|
||||
#[display(fmt = "Bad request: {}", _0)]
|
||||
BadRequest(#[error(not(source))] String),
|
||||
|
||||
#[display(fmt = "Gist is empty, at least one file is required to create gist")]
|
||||
GistEmpty,
|
||||
}
|
||||
|
||||
impl From<CredsError> for ServiceError {
|
||||
|
@ -231,6 +237,8 @@ impl ResponseError for ServiceError {
|
|||
ServiceError::EmptyComment => StatusCode::BAD_REQUEST,
|
||||
|
||||
ServiceError::UnauthorizedOperation(_) => StatusCode::UNAUTHORIZED,
|
||||
ServiceError::BadRequest(_) => StatusCode::BAD_REQUEST,
|
||||
ServiceError::GistEmpty => StatusCode::BAD_REQUEST,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue