Improved UI to print malformed requests.
This commit is contained in:
parent
2678ccaf9f
commit
6f4f4b234a
25
src/authd.cr
25
src/authd.cr
@ -9,6 +9,15 @@ require "./user.cr"
|
||||
class AuthD::Exception < Exception
|
||||
end
|
||||
|
||||
class AuthD::MalformedRequest < Exception
|
||||
getter ipc_type : Int32
|
||||
getter payload : String
|
||||
|
||||
def initialize(@ipc_type, @payload)
|
||||
@message = "malformed payload"
|
||||
end
|
||||
end
|
||||
|
||||
class AuthD::Response
|
||||
include JSON::Serializable
|
||||
|
||||
@ -133,9 +142,11 @@ class AuthD::Response
|
||||
payload = String.new message.payload
|
||||
type = Type.new message.utype.to_i
|
||||
|
||||
requests.find(&.type.==(type)).try &.from_json(payload)
|
||||
rescue e : JSON::ParseException
|
||||
raise Exception.new "malformed request"
|
||||
begin
|
||||
requests.find(&.type.==(type)).try &.from_json(payload)
|
||||
rescue e : JSON::ParseException
|
||||
raise MalformedRequest.new message.utype.to_i, payload
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -307,9 +318,11 @@ class AuthD::Request
|
||||
payload = String.new message.payload
|
||||
type = Type.new message.utype.to_i
|
||||
|
||||
requests.find(&.type.==(type)).try &.from_json(payload)
|
||||
rescue e : JSON::ParseException
|
||||
raise Exception.new "malformed request"
|
||||
begin
|
||||
requests.find(&.type.==(type)).try &.from_json(payload)
|
||||
rescue e : JSON::ParseException
|
||||
raise MalformedRequest.new message.utype.to_i, payload
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
11
src/main.cr
11
src/main.cr
@ -352,13 +352,18 @@ class AuthD::Service
|
||||
|
||||
response = handle_request request, event.connection
|
||||
|
||||
info ">> #{response.class.name.sub /^Response::/, ""}"
|
||||
|
||||
event.connection.send response
|
||||
rescue e : MalformedRequest
|
||||
error "#{e.message}"
|
||||
error " .. type was: #{e.ipc_type}"
|
||||
error " .. payload was: #{e.payload}"
|
||||
response = Response::Error.new e.message
|
||||
rescue e
|
||||
error "#{e.message}"
|
||||
event.connection.send Response::Error.new e.message
|
||||
response = Response::Error.new e.message
|
||||
end
|
||||
|
||||
info ">> #{response.class.name.sub /^Response::/, ""}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user