mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Content Server: Proper error message for pick a random book
Raise a 404 instead of a 500 if the user tries pick a random book on an empty library.
This commit is contained in:
parent
811b210303
commit
1fc537054b
@ -906,8 +906,11 @@ class BrowseServer(object):
|
||||
@Endpoint()
|
||||
def browse_random(self, *args, **kwargs):
|
||||
import random
|
||||
book_id = random.choice(self.db.search_getting_ids(
|
||||
'', self.search_restriction))
|
||||
try:
|
||||
book_id = random.choice(self.db.search_getting_ids(
|
||||
'', self.search_restriction))
|
||||
except IndexError:
|
||||
raise cherrypy.HTTPError(404, 'This library has no books')
|
||||
ans = self.browse_render_details(book_id, add_random_button=True)
|
||||
return self.browse_template('').format(
|
||||
title='', script='book();', main=ans)
|
||||
|
Loading…
x
Reference in New Issue
Block a user