From e55b5da83ad44cccb9aaafffaff263083343a37f Mon Sep 17 00:00:00 2001 From: Max Truxa Date: Thu, 21 Dec 2023 17:10:22 +0000 Subject: [PATCH] Fix handling of optional query filter options Query filter options like `sortOrder` and `sortBy` are optional. The existing code handled these incorrectly, causing 500 responses. --- vscoffline/server.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vscoffline/server.py b/vscoffline/server.py index 3ffbb2f..7f7bee9 100644 --- a/vscoffline/server.py +++ b/vscoffline/server.py @@ -206,10 +206,10 @@ def on_post(self, req, resp): #flags = vsc.QueryFlags.NoneDefined criteria = req.media['filters'][0]['criteria'] - if req.media['filters'][0]['sortOrder']: + if req.media['filters'][0].get('sortOrder'): sortorder = vsc.SortOrder(req.media['filters'][0]['sortOrder']) - if req.media['filters'][0]['sortBy']: + if req.media['filters'][0].get('sortBy'): sortby = vsc.SortBy(req.media['filters'][0]['sortBy']) # Flags can be used for version management, but it appears the client doesn't care what's sent back @@ -217,8 +217,8 @@ def on_post(self, req, resp): # flags = vsc.QueryFlags(req.media['flags']) # Unused - #pagenumber = req.media['filters'][0]['pageNumber'] - #pagesize = req.media['filters'][0]['pageSize'] + #pagenumber = req.media['filters'][0].get('pageNumber', 0) + #pagesize = req.media['filters'][0].get('pageSize', 500) #log.info(f'CRITERIA {criteria}, flags {flags}, sortby {sortby}, sortorder {sortorder}') # If no order specified, default to InstallCount (e.g. popular first)