adding handling of exceptions when the request fails (not a nice solution atm, as we do not actively wait for the request failure, but follow up errors)

passing through http codes from backend to frontend
fixing path to environments repository in tiltfile
This commit is contained in:
Sheldan
2024-01-22 22:11:13 +01:00
parent b42f3cca24
commit 627e52776b
9 changed files with 84 additions and 59 deletions

View File

@@ -32,8 +32,8 @@ docker_build(registry + 'gw2-tools-database', 'gw2-tools-backend/database/src/ma
local('cd tilt/gw2-tools-dev && helm dep up') local('cd tilt/gw2-tools-dev && helm dep up')
k8s_yaml(helm('tilt/gw2-tools-dev', values=[ k8s_yaml(helm('tilt/gw2-tools-dev', values=[
'./../drr-environments/argocd/apps/gw2-tools/values/local/values.yaml', './../gw2-tools-environments/argocd/apps/gw2-tools/values/local/values.yaml',
'./../drr-environments/argocd/apps/gw2-tools/values/local/values.secrets.yaml' 'secrets://./../gw2-tools-environments/argocd/apps/gw2-tools/values/local/values.secrets.yaml'
])) ]))
k8s_resource('backend', port_forwards='5005:5005', labels=['applications']) k8s_resource('backend', port_forwards='5005:5005', labels=['applications'])

View File

@@ -8,7 +8,7 @@ backend:
pullPolicy: Always pullPolicy: Always
image: gw2-tools-backend image: gw2-tools-backend
# Overrides the image tag whose default is the chart appVersion. # Overrides the image tag whose default is the chart appVersion.
tag: 0.0.1 tag:
debug: debug:
enabled: true enabled: true
port: 5005 port: 5005
@@ -73,7 +73,7 @@ dbDeployment:
image: image:
repository: harbor.sheldan.dev/gw2 repository: harbor.sheldan.dev/gw2
image: gw2-tools-database image: gw2-tools-database
tag: 0.0.1 tag:
pullPolicy: Always pullPolicy: Always
cacheJob: cacheJob:
@@ -101,7 +101,7 @@ frontend:
pullPolicy: IfNotPresent pullPolicy: IfNotPresent
image: gw2-tools-frontend image: gw2-tools-frontend
# Overrides the image tag whose default is the chart appVersion. # Overrides the image tag whose default is the chart appVersion.
tag: 0.0.1 tag:
port: 8080 port: 8080
service: service:
type: ClusterIP type: ClusterIP

View File

@@ -51,8 +51,8 @@ def get_account_characters():
api_key = request.headers.get(api_key_header_name) api_key = request.headers.get(api_key_header_name)
headers = {'api-key': api_key} headers = {'api-key': api_key}
logging.info("Loading characters") logging.info("Loading characters")
inventory_response = requests.get(f'{characters_url}', headers=headers) characters_response = requests.get(f'{characters_url}', headers=headers)
return inventory_response.text return characters_response.text, characters_response.status_code
@app.route('/inventory/') @app.route('/inventory/')
@@ -62,7 +62,7 @@ def get_account_inventory():
headers = {'api-key': api_key} headers = {'api-key': api_key}
logging.info("Rendering inventory of full account") logging.info("Rendering inventory of full account")
inventory_response = requests.get(f'{inventory_url}', headers=headers) inventory_response = requests.get(f'{inventory_url}', headers=headers)
text = inventory_response.text text = inventory_response.text, inventory_response.status_code
return text return text
@@ -73,7 +73,7 @@ def get_account_wallet():
headers = {'api-key': api_key} headers = {'api-key': api_key}
logging.info("Rendering wallet of account") logging.info("Rendering wallet of account")
wallet_response = requests.get(f'{wallet_url}', headers=headers) wallet_response = requests.get(f'{wallet_url}', headers=headers)
return wallet_response.text return wallet_response.text, wallet_response.status_code
@app.route('/bank/') @app.route('/bank/')
@@ -83,7 +83,7 @@ def get_account_bank():
headers = {'api-key': api_key} headers = {'api-key': api_key}
logging.info("Rendering bank of account") logging.info("Rendering bank of account")
bank_response = requests.get(f'{bank_url}', headers=headers) bank_response = requests.get(f'{bank_url}', headers=headers)
return bank_response.text return bank_response.text, bank_response.status_code
@app.route('/materials/') @app.route('/materials/')
@@ -93,7 +93,7 @@ def get_materials():
headers = {'api-key': api_key} headers = {'api-key': api_key}
logging.info("Rendering materials of account") logging.info("Rendering materials of account")
materials_response = requests.get(f'{materials_url}', headers=headers) materials_response = requests.get(f'{materials_url}', headers=headers)
return materials_response.text return materials_response.text, materials_response.status_code
@app.route('/sharedInventory/') @app.route('/sharedInventory/')
@@ -103,7 +103,7 @@ def get_shared_inventory():
headers = {'api-key': api_key} headers = {'api-key': api_key}
logging.info("Rendering shared inventory of account") logging.info("Rendering shared inventory of account")
shared_inventory_response = requests.get(f'{shared_inventory_url}', headers=headers) shared_inventory_response = requests.get(f'{shared_inventory_url}', headers=headers)
return shared_inventory_response.text return shared_inventory_response.text, shared_inventory_response.status_code
@app.route('/submissionTemplates/') @app.route('/submissionTemplates/')
@@ -111,14 +111,14 @@ def get_submission_templates():
logging.info("Rendering submission templates") logging.info("Rendering submission templates")
parameters_query = request.query_string.decode() parameters_query = request.query_string.decode()
submission_templates_response = requests.get(f'{submission_templates_url}?{parameters_query}') submission_templates_response = requests.get(f'{submission_templates_url}?{parameters_query}')
return submission_templates_response.text return submission_templates_response.text, submission_templates_response.status_code
@app.route('/itemRates/') @app.route('/itemRates/')
def get_item_rates(): def get_item_rates():
logging.info("Rendering item rates") logging.info("Rendering item rates")
item_rates_response = requests.get(f'{itemRates_url}') item_rates_response = requests.get(f'{itemRates_url}')
return item_rates_response.text return item_rates_response.text, item_rates_response.status_code
@app.route('/openings/', methods=['POST']) @app.route('/openings/', methods=['POST'])
@@ -128,7 +128,7 @@ def create_opening():
headers = {'api-key': api_key, 'Content-Type': 'application/json'} headers = {'api-key': api_key, 'Content-Type': 'application/json'}
logging.info("Creating opening") logging.info("Creating opening")
openings_response = requests.post(f'{openings_url}', body, headers=headers) openings_response = requests.post(f'{openings_url}', body, headers=headers)
return openings_response.text return openings_response.text, openings_response.status_code
@app.route('/openings/', methods=['GET']) @app.route('/openings/', methods=['GET'])
@@ -138,7 +138,7 @@ def get_openings():
headers = {'api-key': api_key} headers = {'api-key': api_key}
logging.info("Loading openings") logging.info("Loading openings")
bank_response = requests.get(f'{openings_url}?{parameters_query}', headers=headers) bank_response = requests.get(f'{openings_url}?{parameters_query}', headers=headers)
return bank_response.text return bank_response.text, bank_response.status_code
@app.route('/openings/<opening_id>', methods=['DELETE']) @app.route('/openings/<opening_id>', methods=['DELETE'])
@@ -147,7 +147,7 @@ def delete_opening(opening_id):
headers = {'api-key': api_key} headers = {'api-key': api_key}
logging.info(f"Deleting opening {opening_id}") logging.info(f"Deleting opening {opening_id}")
bank_response = requests.delete(f'{openings_url}/{opening_id}', headers=headers) bank_response = requests.delete(f'{openings_url}/{opening_id}', headers=headers)
return bank_response.text return bank_response.text, bank_response.status_code
@app.route('/inventory/<character_name>/') @app.route('/inventory/<character_name>/')
@@ -157,7 +157,7 @@ def get_character_inventory(character_name):
headers = {'api-key': api_key} headers = {'api-key': api_key}
logging.info("rendering inventory of individual character.") logging.info("rendering inventory of individual character.")
inventory_response = requests.get(f'{inventory_url}/{character_name}', headers=headers) inventory_response = requests.get(f'{inventory_url}/{character_name}', headers=headers)
return inventory_response.text return inventory_response.text, inventory_response.status_code
if __name__ == "__main__": if __name__ == "__main__":

View File

@@ -42,19 +42,23 @@ export function Bank() {
async function reloadBank() { async function reloadBank() {
setBankLoading(true) setBankLoading(true)
const bankSlots = await fetchBank(); try {
if(!config.locked) { const bankSlots = await fetchBank();
const bankState = { if(!config.locked) {
slots: bankSlots, const bankState = {
addedSlots: [], slots: bankSlots,
removedSlots: [] addedSlots: [],
removedSlots: []
}
dispatch(setBank(bankState))
} else {
const [slotsToAdd, slotsToRemove, slotsToUpdate] = calculateBankDifferences(bank, bankSlots, config.mocking);
dispatch(setRemovedBankSlots(slotsToRemove))
dispatch(setAddedBankSlots(slotsToAdd))
dispatch(updateChangedBankSlots(slotsToUpdate))
} }
dispatch(setBank(bankState)) } catch (e) {
} else { console.log(e)
const [slotsToAdd, slotsToRemove, slotsToUpdate] = calculateBankDifferences(bank, bankSlots, config.mocking);
dispatch(setRemovedBankSlots(slotsToRemove))
dispatch(setAddedBankSlots(slotsToAdd))
dispatch(updateChangedBankSlots(slotsToUpdate))
} }
setBankLoading(false) setBankLoading(false)
} }

View File

@@ -82,8 +82,12 @@ export const CharacterInventory = ({character}) => {
async function updateCharacter() { async function updateCharacter() {
setCharacterLoading(true) setCharacterLoading(true)
await reloadCharacterInventory(); try {
await reloadWallet(); await reloadCharacterInventory();
await reloadWallet();
} catch (e) {
console.log(e)
}
setCharacterLoading(false) setCharacterLoading(false)
} }

View File

@@ -123,11 +123,15 @@ export function ItemDifference() {
async function fetchInformation() { async function fetchInformation() {
dispatch(setLoading(true)) dispatch(setLoading(true))
await updateWallet() try {
await updateBank() await updateWallet()
await updateMaterials() await updateBank()
await updatedSharedInventory() await updateMaterials()
await updateInventoryCharacterSpecific() await updatedSharedInventory()
await updateInventoryCharacterSpecific()
} catch (e) {
console.log(e)
}
dispatch(setLoading(false)) dispatch(setLoading(false))
} }

View File

@@ -48,21 +48,26 @@ export function Materials() {
async function reloadMaterials() { async function reloadMaterials() {
setMaterialsLoading(true) setMaterialsLoading(true)
const materialSlots = await fetchMaterials(); try {
if(!config.locked) { const materialSlots = await fetchMaterials();
const materialsState = { if(!config.locked) {
slots: materialSlots, const materialsState = {
addedSlots: [], slots: materialSlots,
removedSlots: [] addedSlots: [],
} removedSlots: []
dispatch(setMaterials(materialsState)) }
} else { dispatch(setMaterials(materialsState))
const [slotsToAdd, slotsToRemove, slotsToUpdate] = calculateMaterialsDifference(materials, materialSlots, config.mocking); } else {
const [slotsToAdd, slotsToRemove, slotsToUpdate] = calculateMaterialsDifference(materials, materialSlots, config.mocking);
dispatch(setRemovedMaterialSlots(slotsToRemove)) dispatch(setRemovedMaterialSlots(slotsToRemove))
dispatch(setAddedMaterialSlots(slotsToAdd)) dispatch(setAddedMaterialSlots(slotsToAdd))
dispatch(updateChangedMaterialSlots(slotsToUpdate)) dispatch(updateChangedMaterialSlots(slotsToUpdate))
}
} catch (e) {
console.log(e)
} }
setMaterialsLoading(false) setMaterialsLoading(false)
} }

View File

@@ -107,12 +107,16 @@ export function OpeningSubmission() {
async function submitOpening() { async function submitOpening() {
dispatch(setLoading(true)) dispatch(setLoading(true))
const submissionBody = {} try {
submissionBody.items = getChanges(); const submissionBody = {}
submissionBody.description = openingDescription; submissionBody.items = getChanges();
await fetcher("openings", {apiKey: apiKey, method: "POST", body: JSON.stringify(submissionBody), headers: {"Content-Type": "application/json"}}) submissionBody.description = openingDescription;
setOpeningDescription("") await fetcher("openings", {apiKey: apiKey, method: "POST", body: JSON.stringify(submissionBody), headers: {"Content-Type": "application/json"}})
toast('Opening has been submitted.') setOpeningDescription("")
toast('Opening has been submitted.')
} catch (e) {
console.log(e)
}
dispatch(setLoading(false)) dispatch(setLoading(false))
} }

View File

@@ -72,9 +72,13 @@ export function OpeningOverview() {
} }
async function loadOpenings() { async function loadOpenings() {
setOpeningsLoading(true) try {
const openings = await fetchOpenings(); setOpeningsLoading(true)
dispatch(setOpenings(openings)) const openings = await fetchOpenings();
dispatch(setOpenings(openings))
} catch (e) {
console.log(e)
}
setOpeningsLoading(false) setOpeningsLoading(false)
} }