Implémenter NotFoundResponse()
This commit is contained in:
parent
83d669b7a5
commit
ba43df3e31
2 changed files with 11 additions and 23 deletions
|
@ -127,13 +127,7 @@ func HandleV1BucketRead(c echo.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !allowed {
|
if !allowed {
|
||||||
/* TODO models.NotFoundResponse
|
return c.JSON(http.StatusNotFound, models.NotFoundResponse())
|
||||||
response.StatusCode = http.StatusNotFound
|
|
||||||
response.Message = "Not Found"
|
|
||||||
|
|
||||||
return c.JSON(response.StatusCode, response)
|
|
||||||
*/
|
|
||||||
return c.JSON(http.StatusNotFound, map[string]string{"message": "Not Found"})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
@ -159,8 +153,7 @@ func HandleV1BucketRead(c echo.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
// TODO models.NotFoundResponse
|
return c.JSON(http.StatusNotFound, models.NotFoundResponse())
|
||||||
return c.JSON(http.StatusNotFound, map[string]string{"message": "Not Found"})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
objectCh := mediaClient.MinioClient.ListObjects(ctx, bucket, minio.ListObjectsOptions{})
|
objectCh := mediaClient.MinioClient.ListObjects(ctx, bucket, minio.ListObjectsOptions{})
|
||||||
|
@ -210,7 +203,7 @@ func HandleV1DocumentCreate(c echo.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !allowed {
|
if !allowed {
|
||||||
return c.JSON(http.StatusNotFound, map[string]string{"message": "Not Found"})
|
return c.JSON(http.StatusNotFound, models.NotFoundResponse())
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
@ -279,7 +272,7 @@ func HandleV1DocumentRead(c echo.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !allowed {
|
if !allowed {
|
||||||
return c.JSON(http.StatusNotFound, map[string]string{"message": "Not Found"})
|
return c.JSON(http.StatusNotFound, models.NotFoundResponse())
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
@ -300,7 +293,7 @@ func HandleV1DocumentRead(c echo.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !bucket_exists {
|
if !bucket_exists {
|
||||||
return c.JSON(http.StatusNotFound, map[string]string{"message": "Not Found"})
|
return c.JSON(http.StatusNotFound, models.NotFoundResponse())
|
||||||
}
|
}
|
||||||
|
|
||||||
document_info, err := mediaClient.MinioClient.StatObject(ctx, bucket, document, minio.StatObjectOptions{})
|
document_info, err := mediaClient.MinioClient.StatObject(ctx, bucket, document, minio.StatObjectOptions{})
|
||||||
|
@ -308,7 +301,7 @@ func HandleV1DocumentRead(c echo.Context) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err.Error() == "The specified key does not exist." {
|
if err.Error() == "The specified key does not exist." {
|
||||||
|
|
||||||
return c.JSON(http.StatusNotFound, map[string]string{"message": "Not Found"})
|
return c.JSON(http.StatusNotFound, models.NotFoundResponse())
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(http.StatusInternalServerError, map[string]interface{}{
|
return c.JSON(http.StatusInternalServerError, map[string]interface{}{
|
||||||
|
@ -356,12 +349,7 @@ func HandleV1DocumentDelete(c echo.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !allowed {
|
if !allowed {
|
||||||
/*
|
return c.JSON(http.StatusNotFound, models.NotFoundResponse())
|
||||||
return c.JSON(http.StatusBadRequest, map[string]string{
|
|
||||||
"message": "Bucket is not allowed in server.documents.buckets",
|
|
||||||
})
|
|
||||||
*/
|
|
||||||
return c.JSON(http.StatusNotFound, map[string]string{"message": "Not Found"})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
@ -382,14 +370,14 @@ func HandleV1DocumentDelete(c echo.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !bucket_exists {
|
if !bucket_exists {
|
||||||
return c.JSON(http.StatusNotFound, map[string]string{"message": "Not Found"})
|
return c.JSON(http.StatusNotFound, models.NotFoundResponse())
|
||||||
}
|
}
|
||||||
|
|
||||||
document_info, err := mediaClient.MinioClient.StatObject(ctx, bucket, document, minio.StatObjectOptions{})
|
document_info, err := mediaClient.MinioClient.StatObject(ctx, bucket, document, minio.StatObjectOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err.Error() == "The specified key does not exist." {
|
if err.Error() == "The specified key does not exist." {
|
||||||
|
|
||||||
return c.JSON(http.StatusNotFound, map[string]string{"message": "Not Found"})
|
return c.JSON(http.StatusNotFound, models.NotFoundResponse())
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(http.StatusInternalServerError, map[string]interface{}{
|
return c.JSON(http.StatusInternalServerError, map[string]interface{}{
|
||||||
|
|
|
@ -130,7 +130,7 @@ func HandleFormulaires(c echo.Context) error {
|
||||||
func HandlePublicDocumentation(c echo.Context) error {
|
func HandlePublicDocumentation(c echo.Context) error {
|
||||||
client, err := api.NewApiClientFromViper()
|
client, err := api.NewApiClientFromViper()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusNotFound, map[string]string{"message": "Not Found"})
|
return c.JSON(http.StatusNotFound, models.NotFoundResponse())
|
||||||
}
|
}
|
||||||
|
|
||||||
bucket := c.Param("bucket")
|
bucket := c.Param("bucket")
|
||||||
|
@ -138,7 +138,7 @@ func HandlePublicDocumentation(c echo.Context) error {
|
||||||
|
|
||||||
result, err := client.Call(http.MethodGet, fmt.Sprintf("/v1/bucket/%s/%s", bucket, document))
|
result, err := client.Call(http.MethodGet, fmt.Sprintf("/v1/bucket/%s/%s", bucket, document))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusNotFound, map[string]string{"message": "Not Found"})
|
return c.JSON(http.StatusNotFound, models.NotFoundResponse())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if result can fit inside a map containing a message
|
// Check if result can fit inside a map containing a message
|
||||||
|
|
Loading…
Reference in a new issue