#211 [BUG] 在測試 /v1/token 時伺服器 Crash 了
*發生了什麼事? / The Problem*
在傳送 /v1/token 取得 token 時,如果只傳送 POST 而沒有傳送正確的參數的話,伺服器會出現錯誤。
*如何重現 / To Reproduce*
1. 首先建置好含 home bbs 資料的環境
2. `curl 'localhost:8081/v1/token' -d ''`
3. 接著就會伺服器端就會什麼都沒回應,如果是 nginx 做中介的場合會得到 500 Server Error
*預期的行為 / Expected behavior*
不應該出現 Server Error, 應該要出現缺少參數的 Error 以及明確指出缺少什麼參數
*螢幕截圖 / Screenshots*
```
2021/06/04 22:05:43 postToken parse form err: %!w(<nil>)
2021/06/04 22:05:43 found user: &{0xc000178c40}
2021/06/04 22:05:43 password
2021/06/04 22:05:43 http: panic serving [::1]:51211: runtime error: slice bounds out of range [:2] with length 0
goroutine 14 [running]:
net/http.(*conn).serve.func1(0xc00011b040)
/usr/local/Cellar/go/1.16.2/libexec/src/net/http/server.go:1824 +0x153
panic(0x136a8c0, 0xc0000144c8)
/usr/local/Cellar/go/1.16.2/libexec/src/runtime/panic.go:971 +0x499
<http://github.com/Ptt-official-app/go-bbs/pttbbs.(*Userec).VerifyPassword|github.com/Ptt-official-app/go-bbs/pttbbs.(*Userec).VerifyPassword>(0xc000178c40, 0x0, 0x0, 0x0, 0x0)
/Users/tih/go/pkg/mod/github.com/!ptt-official-app/go-bbs@v0.3.3/pttbbs/passwd.go:157 +0x219
<http://github.com/Ptt-official-app/Ptt-backend/internal/delivery/http.(*Delivery).verifyPassword(0xc000022880|github.com/Ptt-official-app/Ptt-backend/internal/delivery/http.(*Delivery).verifyPassword(0xc000022880>, 0x1400188, 0xc000013d10, 0x0, 0x0, 0x1400188, 0xc000013d10)
/Users/tih/localgitrepos/Ptt-backend/internal/delivery/http/route_token.go:77 +0xd0
<http://github.com/Ptt-official-app/Ptt-backend/internal/delivery/http.(*Delivery).postToken(0xc000022880|github.com/Ptt-official-app/Ptt-backend/internal/delivery/http.(*Delivery).postToken(0xc000022880>, 0x13fd970, 0xc000180540, 0xc00010eb00)
/Users/tih/localgitrepos/Ptt-backend/internal/delivery/http/route_token.go:43 +0x209
<http://github.com/Ptt-official-app/Ptt-backend/internal/delivery/http.(*Delivery).routeToken(...)|github.com/Ptt-official-app/Ptt-backend/internal/delivery/http.(*Delivery).routeToken(...)>
/Users/tih/localgitrepos/Ptt-backend/internal/delivery/http/route.go:22
net/http.HandlerFunc.ServeHTTP(0xc000194120, 0x13fd970, 0xc000180540, 0xc00010eb00)
/usr/local/Cellar/go/1.16.2/libexec/src/net/http/server.go:2069 +0x44
net/http.(*ServeMux).ServeHTTP(0xc00005a7c0, 0x13fd970, 0xc000180540, 0xc00010eb00)
/usr/local/Cellar/go/1.16.2/libexec/src/net/http/server.go:2448 +0x1ad
net/http.serverHandler.ServeHTTP(0xc0001800e0, 0x13fd970, 0xc000180540, 0xc00010eb00)
/usr/local/Cellar/go/1.16.2/libexec/src/net/http/server.go:2887 +0xa3
net/http.(*conn).serve(0xc00011b040, 0x13fe080, 0xc00005ac40)
/usr/local/Cellar/go/1.16.2/libexec/src/net/http/server.go:1952 +0x8cd
created by net/http.(*Server).Serve
/usr/local/Cellar/go/1.16.2/libexec/src/net/http/server.go:3013 +0x39b
```
<https://user-images.githubusercontent.com/600238/120814983-fe219980-c581-11eb-873c-4f745ef535f6.png|截圖 2021-06-04 下午10 12 40>
*開發環境 / Environment*
• OS: macOS 11.4
• golang version: 1.16.2
• package version: <https://github.com/Ptt-official-app/Ptt-backend/commit/02866f0100f50c706386ab158bf0060496b81629|02866f0>
• 測試工具: curl
👍 2