Skip to content

Commit f9f1b24

Browse files
author
Alê Borba
committed
Retornando 404 para pacote não encontrado.
1 parent 4be5b31 commit f9f1b24

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

PostmonServer.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,25 @@ def verifica_cep(cep):
5656

5757
@route('/v1/track/ect/<track>')
5858
def track_ect(track):
59-
encomenda = Correios.encomenda(track)
59+
try:
60+
encomenda = Correios.encomenda(track)
61+
62+
result = []
6063

61-
result = []
64+
for status in encomenda.status:
65+
resposta = dict()
66+
67+
resposta['data'] = status.data
68+
resposta['local'] = status.local
69+
resposta['situacao'] = status.situacao
70+
resposta['detalhes'] = status.detalhes
6271

63-
for status in encomenda.status:
64-
resposta = dict()
65-
66-
resposta['data'] = status.data
67-
resposta['local'] = status.local
68-
resposta['situacao'] = status.situacao
69-
resposta['detalhes'] = status.detalhes
72+
result.append(resposta)
7073

71-
result.append(resposta)
74+
return json.dumps(result)
7275

73-
return json.dumps(result)
76+
except AttributeError:
77+
response.status = '404 O pacote %s informado não pode ser localizado' %track
7478

7579
def _standalone(port=9876):
7680
run(host='localhost', port=port)

0 commit comments

Comments
 (0)