lab5 done
This commit is contained in:
@@ -33,7 +33,7 @@ func (h *Chat) uploadAttachment(c echo.Context) error {
|
||||
if err != nil {
|
||||
return h.useCaseError(c, err)
|
||||
}
|
||||
return c.JSON(http.StatusCreated, a)
|
||||
return c.JSON(http.StatusAccepted, a)
|
||||
}
|
||||
func (h *Chat) getAttachment(c echo.Context) error {
|
||||
a, err := h.attachments.Get(c.Request().Context(), c.Param("attachment_id"), authenticatedUser(c).ID)
|
||||
@@ -51,8 +51,15 @@ func (h *Chat) attachmentContent(c echo.Context) error {
|
||||
if err != nil {
|
||||
return h.invalid(c, "Некорректный variant")
|
||||
}
|
||||
if present && variant != "original" {
|
||||
return h.writeError(c, 404, "not_found", "Вариант не найден")
|
||||
if a.Status != "ready" {
|
||||
return h.writeError(c, 409, "conflict", "Вложение не готово")
|
||||
}
|
||||
if !present {
|
||||
variant = "original"
|
||||
}
|
||||
a, err = h.attachments.Variant(a, variant)
|
||||
if err != nil {
|
||||
return h.useCaseError(c, err)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(c.Request().Context(), 45*time.Second)
|
||||
defer cancel()
|
||||
|
||||
@@ -35,6 +35,9 @@ func (h *Chat) useCaseError(c echo.Context, err error) error {
|
||||
switch applicationError.Code {
|
||||
case "unsupported_media_type":
|
||||
status = http.StatusUnsupportedMediaType
|
||||
case "rate_limited":
|
||||
status = http.StatusTooManyRequests
|
||||
c.Response().Header().Set("Retry-After", "2")
|
||||
case "payload_too_large":
|
||||
status = http.StatusRequestEntityTooLarge
|
||||
case domain.ErrorUnavailable:
|
||||
|
||||
Reference in New Issue
Block a user