Skip to content
Merged
Prev Previous commit
Next Next commit
Handle no results
  • Loading branch information
presleyp committed Nov 18, 2022
commit eec1a6131b374517c46aa9cd62dd8cef229c3280
9 changes: 9 additions & 0 deletions coderd/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ func (api *API) auditLogs(rw http.ResponseWriter, r *http.Request) {
httpapi.InternalServerError(rw, err)
return
}
// GetAuditLogsOffset does not return ErrNoRows because it uses a window function to get the count.
// So we need to check if the dblogs is empty and return an empty array if so.
if len(dblogs) == 0 {
httpapi.Write(ctx, rw, http.StatusOK, codersdk.AuditLogResponse{
AuditLogs: []codersdk.AuditLog{},
Count: 0,
})
return
}

httpapi.Write(ctx, rw, http.StatusOK, codersdk.AuditLogResponse{
AuditLogs: convertAuditLogs(dblogs),
Expand Down