mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
fix error showing up when an invalid channel was provided
This commit is contained in:
parent
70e8081045
commit
3678bffd5b
|
@ -19,16 +19,16 @@ func (app *application) startRouter() {
|
||||||
|
|
||||||
func (app *application) channelCommandsRoute(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
func (app *application) channelCommandsRoute(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
channel := ps.ByName("channel")
|
channel := ps.ByName("channel")
|
||||||
|
var cs []string
|
||||||
|
var text string
|
||||||
|
|
||||||
command, err := app.Models.Commands.GetAllChannel(channel)
|
command, err := app.Models.Commands.GetAllChannel(channel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.Log.Errorw("Error trying to retrieve all timers from database", err)
|
app.Log.Errorw("Error trying to retrieve all commands for a channel from database", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// The slice of timers is only used to log them at
|
// The slice of timers is only used to log them at
|
||||||
// the start so it looks a bit nicer.
|
// the start so it looks a bit nicer.
|
||||||
var cs []string
|
|
||||||
|
|
||||||
// Iterate over all timers and then add them onto the scheduler.
|
// Iterate over all timers and then add them onto the scheduler.
|
||||||
for i, v := range command {
|
for i, v := range command {
|
||||||
|
@ -59,11 +59,11 @@ func (app *application) channelCommandsRoute(w http.ResponseWriter, r *http.Requ
|
||||||
|
|
||||||
// Add new value to the slice
|
// Add new value to the slice
|
||||||
cs = append(cs, c)
|
cs = append(cs, c)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
text := strings.Join(cs, "")
|
text = strings.Join(cs, "")
|
||||||
fmt.Fprintf(w, fmt.Sprint(text), ps.ByName("name"))
|
fmt.Fprintf(w, fmt.Sprint(text))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *application) statusPageRoute(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
func (app *application) statusPageRoute(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||||
|
|
|
@ -306,7 +306,12 @@ func (c CommandModel) GetAllChannel(channel string) ([]*Command, error) {
|
||||||
&command.Help,
|
&command.Help,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
switch {
|
||||||
|
case errors.Is(err, sql.ErrNoRows):
|
||||||
|
return nil, ErrRecordNotFound
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Add the single movie struct onto the slice.
|
// Add the single movie struct onto the slice.
|
||||||
commands = append(commands, &command)
|
commands = append(commands, &command)
|
||||||
|
|
Loading…
Reference in a new issue