playmak3r commited on
Commit
001000b
1 Parent(s): 07912dd

feat: add error feedback

Browse files
Files changed (2) hide show
  1. server/app.py +1 -1
  2. src/Home/index.tsx +3 -4
server/app.py CHANGED
@@ -63,7 +63,7 @@ def translate_api():
63
  redis_client.lpush(queue_key, input_text) # left push
64
  result = query_translation(input_text)
65
  if result is not None: return jsonify({ "text": result })
66
- else: return Response(status= 500)
67
  return Response(status= 400)
68
 
69
 
 
63
  redis_client.lpush(queue_key, input_text) # left push
64
  result = query_translation(input_text)
65
  if result is not None: return jsonify({ "text": result })
66
+ else: return Response(status= 529, response= "Error 529: Server overloaded")
67
  return Response(status= 400)
68
 
69
 
src/Home/index.tsx CHANGED
@@ -22,10 +22,9 @@ export default function App() {
22
  const { text } = input
23
  if (!text || translation.loading) { return null }
24
  if (translation()) { mutate(null) }
25
- const response = await fetch(`/api/translate?text=${text}`, { method: "POST" }).then(response => {
26
- if (response.status === 200) { return response.json() }
27
-
28
- }).then(response => response?.text)
29
  .catch(() => null)
30
 
31
  return { originalText: text, translatedText: response }
 
22
  const { text } = input
23
  if (!text || translation.loading) { return null }
24
  if (translation()) { mutate(null) }
25
+ const response = await fetch(`/api/translate?text=${text}`, { method: "POST" })
26
+ .then(response => response.status===200? response.json() : response.text())
27
+ .then(response => response?.text ?? response)
 
28
  .catch(() => null)
29
 
30
  return { originalText: text, translatedText: response }