# 빈 검색 시 설명 메시지가 표시되지 않습니다

**URL:** https://meta.discourse.org/t/empty-search-does-not-return-descriptive-message/168699
**Category:** Development
**Created:** [10월 30, 2020, 12:21오전 UTC](https://meta.discourse.org/t/empty-search-does-not-return-descriptive-message/168699 "2020-10-30T00:21:14Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![heyallan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/heyallan/32/198583_2.png) [@heyallan](https://meta.discourse.org/u/heyallan)
#### Post date: [10월 30, 2020, 12:21오전 UTC](https://meta.discourse.org/t/empty-search-does-not-return-descriptive-message/168699/1 "2020-10-30T00:21:14Z")

</div>

프론트엔드는 빈 검색을 허용하지 않으며, 검색어가 너무 짧다는 설명을 담은 유용한 메시지를 표시합니다.

그러나 API 엔드포인트는 여전히 빈 검색을 허용하며, 응답은 NULL 값을 가진 JSON 객체와 200 상태 코드입니다.

API가 설명적인 오류 메시지와 함께 400 상태 코드를 반환해야 하지 않나요?

**기대되는 동작:**

```json
// 400 error
{
  "errors": ["요청에 잘못된 매개변수를 제공했습니다: q"],
  "error_type": "invalid_parameters"
}

```

**실제 동작:**

```json
// 200 ok
{
  "grouped_search_result": null
}

```

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [10월 30, 2020, 12:37오전 UTC](https://meta.discourse.org/t/empty-search-does-not-return-descriptive-message/168699/2 "2020-10-30T00:37:12Z")

</div>

API는 분명히 여기서 개선될 수 있지만, 쿼리 루트는 많은 인수를 허용합니다:

> <https://github.com/discourse/discourse/blob/eed9561840120ea2c77c50fbc8fa61ba0a123b1e/app/controllers/search_controller.rb#L99-L114>

여기서는 min\_search\_term\_length가 필수 요구 사항인지, 선택 사항인지에 대해 매우 신중하게 확인해야 합니다.

---

<div class="post-metadata">

### Author: ![heyallan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/heyallan/32/198583_2.png) [@heyallan](https://meta.discourse.org/u/heyallan)
#### Post date: [10월 31, 2020, 10:34오후 UTC](https://meta.discourse.org/t/empty-search-does-not-return-descriptive-message/168699/3 "2020-10-31T22:34:18Z")

</div>

@sam 감사합니다

현재 상태는 다음과 같습니다:

- 빈 검색은 API에서 처리되지 않는 상태입니다.
- 검색 엔드포인트는 검색어를 받는 동시에 메타데이터 인자(사용자, 카테고리, 태그 등)도 받습니다.
- 메타데이터 인자는 API 문서에记载되어 있지 않습니다.
- 프론트엔드는 검색을 올바르게 검증하지만, 백엔드 API는 부분적으로만 검증하여 빈 검색이 통과하도록 허용하고 있습니다.
- 어떤 경우든 응답 메시지는 설명적으로 작성되어야 합니다.

이 개요가 도움이 되기를 바랍니다.  
개인적으로 이는 버그라고 생각합니다. 이것이 의도된 동작이라면 놀라울 것입니다.  
어쨌든 감사합니다 ✌
