Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Owo Sugiana
/
async-web
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit a512769d
authored
Mar 15, 2023
by
Owo Sugiana
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
class BaseError ditambah action
1 parent
8d28ba6e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
7 deletions
CHANGES.txt
async_web/exceptions.py
async_web/handlers/default_server.py
async_web/server.py
CHANGES.txt
View file @
a512769
0.2 2023-03-15
--------------
- class BaseError ditambah action
0.1 2023-03-07
--------------
- Kali pertama
async_web/exceptions.py
View file @
a512769
...
...
@@ -9,6 +9,7 @@ def exception_message():
class
BaseError
(
Exception
):
def
__init__
(
self
,
code
,
message
):
def
__init__
(
self
,
code
,
message
,
action
=
''
):
self
.
code
=
code
self
.
message
=
message
self
.
action
=
action
async_web/handlers/default_server.py
View file @
a512769
...
...
@@ -10,12 +10,12 @@ ERR_ACTION = 76
class
ErrKey
(
BaseError
):
def
__init__
(
self
,
message
):
super
()
.
__init__
(
ERR_KEY
,
message
)
super
()
.
__init__
(
ERR_KEY
,
message
,
'login'
)
class
ErrAction
(
BaseError
):
def
__init__
(
self
,
message
):
super
()
.
__init__
(
ERR_ACTION
,
message
)
def
__init__
(
self
,
message
,
action
=
''
):
super
()
.
__init__
(
ERR_ACTION
,
message
,
action
)
class
Handler
:
...
...
@@ -45,7 +45,7 @@ class Handler:
if
action
==
'echo'
:
return
dict
(
action
=
'echo'
,
code
=
0
,
message
=
'OK'
)
msg
=
f
'ERROR action {action} tidak dipahami'
raise
ErrAction
(
msg
)
raise
ErrAction
(
msg
,
action
)
def
get_data
(
self
):
return
dict
()
...
...
async_web/server.py
View file @
a512769
...
...
@@ -152,10 +152,10 @@ def main(argv=sys.argv[1:]):
ws_data
[
cid
]
=
[]
mem_clients
[
cid
]
=
mem_id
except
BaseError
as
e
:
dc
=
dict
(
code
=
e
.
code
,
message
=
e
.
message
)
dc
=
dict
(
code
=
e
.
code
,
message
=
e
.
message
,
action
=
e
.
action
)
except
Exception
:
log_unknown_error
()
dc
=
dict
(
code
=
91
,
message
=
'Login gagal'
)
dc
=
dict
(
code
=
91
,
message
=
'Login gagal'
,
action
=
'login'
)
log_info
(
f
'Encode JSON {dc}'
)
await
kirim_pesan
(
dc
)
return
cid
...
...
@@ -206,6 +206,12 @@ def main(argv=sys.argv[1:]):
del
ws_data
[
client_id
]
break
try
:
async
with
asyncio
.
timeout
(
5
):
await
receive
()
except
asyncio
.
TimeoutError
:
pass
log_info
(
'Koneksi berakhir'
)
try
:
handler
.
close
()
except
Exception
:
log_unknown_error
()
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment