Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Communications Backbone System
communications-backbone
Commits
c6a34801
Commit
c6a34801
authored
2 years ago
by
James Kirk
Browse files
Options
Download
Plain Diff
Merge branch 'improved-errors' into 'dev'
fix: correct error code resp Closes
#32
and
#34
See merge request
!17
parents
8f1dc3b0
0a48aa56
dev
11-add-websockets
master
v1.0.0
v0.1.0
v0.0.1
Pipeline
#108974
passed with stages
in 59 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
10 deletions
+30
-10
endpoints/client.py
endpoints/client.py
+18
-8
endpoints/notify.py
endpoints/notify.py
+6
-1
endpoints/send.py
endpoints/send.py
+6
-1
No files found.
endpoints/client.py
View file @
c6a34801
from
flask_restful
import
Resource
,
request
,
abort
import
logging
from
flask_restful
import
Resource
,
abort
,
request
from
marshmallow
import
Schema
,
fields
import
json
import
os
import
random
import
string
from
werkzeug.exceptions
import
BadRequest
from
models.client_model
import
ClientModel
logging
.
basicConfig
(
level
=
logging
.
INFO
)
logging
.
getLogger
(
"pika"
).
setLevel
(
logging
.
ERROR
)
class
ClientSchema
(
Schema
):
client_id
=
fields
.
Str
(
required
=
True
)
...
...
@@ -37,7 +40,11 @@ class Client(Resource):
return
client
,
204
def
put
(
self
,
client_id
):
args
=
request
.
get_json
()
try
:
args
=
request
.
get_json
()
except
BadRequest
:
abort
(
400
,
message
=
"POSTed body is invalid JSON"
)
errors
=
self
.
schema
.
validate
(
args
)
if
errors
:
abort
(
400
,
message
=
str
(
errors
))
...
...
@@ -63,7 +70,10 @@ class ClientList(Resource):
}
def
post
(
self
):
args
=
request
.
get_json
()
try
:
args
=
request
.
get_json
()
except
BadRequest
:
abort
(
400
,
message
=
"POSTed body is invalid JSON"
)
errors
=
self
.
schema
.
validate
(
args
)
if
errors
:
...
...
@@ -71,7 +81,7 @@ class ClientList(Resource):
client
=
self
.
clients_file
.
find
(
args
[
"client_id"
])
if
client
:
abort
(
40
3
,
message
=
"Duplicate client id: {}"
.
format
(
client_id
))
abort
(
40
9
,
message
=
"Duplicate client id: {}"
.
format
(
args
[
"
client_id
"
]
))
else
:
client
=
self
.
clients_file
.
add
(
args
)
return
client
,
201
This diff is collapsed.
Click to expand it.
endpoints/notify.py
View file @
c6a34801
...
...
@@ -2,6 +2,7 @@ import json
from
flask_restful
import
abort
,
request
from
marshmallow
import
Schema
,
fields
from
werkzeug.exceptions
import
BadRequest
from
endpoints.auth_resource
import
AuthResource
from
rmq
import
write_to_queue
...
...
@@ -20,7 +21,11 @@ class Notify(AuthResource):
self
.
schema
=
NotifySchema
()
def
post
(
self
):
args
=
request
.
get_json
()
try
:
args
=
request
.
get_json
()
except
BadRequest
:
abort
(
400
,
message
=
"POSTed body is invalid JSON"
)
errors
=
self
.
schema
.
validate
(
args
)
if
errors
:
abort
(
400
,
message
=
str
(
errors
))
...
...
This diff is collapsed.
Click to expand it.
endpoints/send.py
View file @
c6a34801
...
...
@@ -2,6 +2,7 @@ import json
from
flask_restful
import
abort
,
request
from
marshmallow
import
Schema
,
fields
from
werkzeug.exceptions
import
BadRequest
from
endpoints.auth_resource
import
AuthResource
from
rmq
import
write_to_queue
...
...
@@ -21,7 +22,11 @@ class Send(AuthResource):
self
.
schema
=
SendSchema
()
def
post
(
self
):
args
=
request
.
get_json
()
try
:
args
=
request
.
get_json
()
except
BadRequest
:
abort
(
400
,
message
=
"POSTed body is invalid JSON"
)
errors
=
self
.
schema
.
validate
(
args
)
if
errors
:
abort
(
400
,
message
=
str
(
errors
))
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
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 comment