Улучшение безопасности и обработки ошибок. Этап 2. #8
This commit is contained in:
@@ -102,9 +102,14 @@ datetime_to_iso8601({{Y,M,D},{H,Min,S}}) ->
|
|||||||
datetime_to_iso8601(_) -> null.
|
datetime_to_iso8601(_) -> null.
|
||||||
|
|
||||||
send_json(Req, Status, Data) ->
|
send_json(Req, Status, Data) ->
|
||||||
|
Headers = #{
|
||||||
|
<<"content-type">> => <<"application/json">>,
|
||||||
|
<<"access-control-allow-origin">> => <<"*">>,
|
||||||
|
<<"access-control-expose-headers">> => <<"Content-Range">>
|
||||||
|
},
|
||||||
Body = jsx:encode(Data),
|
Body = jsx:encode(Data),
|
||||||
Req2 = cowboy_req:reply(Status, #{<<"content-type">> => <<"application/json">>}, Body, Req),
|
cowboy_req:reply(Status, Headers, Body, Req),
|
||||||
{ok, Req2, []}.
|
{ok, Body, []}.
|
||||||
|
|
||||||
send_error(Req, Code, Message) ->
|
send_error(Req, Code, Message) ->
|
||||||
Body = jsx:encode(#{error => Message}),
|
Body = jsx:encode(#{error => Message}),
|
||||||
|
|||||||
@@ -117,8 +117,13 @@ datetime_to_iso8601({{Year, Month, Day}, {Hour, Minute, Second}}) ->
|
|||||||
datetime_to_iso8601(undefined) -> undefined.
|
datetime_to_iso8601(undefined) -> undefined.
|
||||||
|
|
||||||
send_json(Req, Status, Data) ->
|
send_json(Req, Status, Data) ->
|
||||||
|
Headers = #{
|
||||||
|
<<"content-type">> => <<"application/json">>,
|
||||||
|
<<"access-control-allow-origin">> => <<"*">>,
|
||||||
|
<<"access-control-expose-headers">> => <<"Content-Range">>
|
||||||
|
},
|
||||||
Body = jsx:encode(Data),
|
Body = jsx:encode(Data),
|
||||||
cowboy_req:reply(Status, #{<<"content-type">> => <<"application/json">>}, Body, Req),
|
cowboy_req:reply(Status, Headers, Body, Req),
|
||||||
{ok, Body, []}.
|
{ok, Body, []}.
|
||||||
|
|
||||||
send_error(Req, Status, Message) ->
|
send_error(Req, Status, Message) ->
|
||||||
|
|||||||
@@ -94,8 +94,13 @@ datetime_to_iso8601({{Year, Month, Day}, {Hour, Minute, Second}}) ->
|
|||||||
datetime_to_iso8601(undefined) -> undefined.
|
datetime_to_iso8601(undefined) -> undefined.
|
||||||
|
|
||||||
send_json(Req, Status, Data) ->
|
send_json(Req, Status, Data) ->
|
||||||
|
Headers = #{
|
||||||
|
<<"content-type">> => <<"application/json">>,
|
||||||
|
<<"access-control-allow-origin">> => <<"*">>,
|
||||||
|
<<"access-control-expose-headers">> => <<"Content-Range">>
|
||||||
|
},
|
||||||
Body = jsx:encode(Data),
|
Body = jsx:encode(Data),
|
||||||
cowboy_req:reply(Status, #{<<"content-type">> => <<"application/json">>}, Body, Req),
|
cowboy_req:reply(Status, Headers, Body, Req),
|
||||||
{ok, Body, []}.
|
{ok, Body, []}.
|
||||||
|
|
||||||
send_error(Req, Status, Message) ->
|
send_error(Req, Status, Message) ->
|
||||||
|
|||||||
@@ -78,8 +78,13 @@ datetime_to_iso8601({{Year, Month, Day}, {Hour, Minute, Second}}) ->
|
|||||||
datetime_to_iso8601(undefined) -> undefined.
|
datetime_to_iso8601(undefined) -> undefined.
|
||||||
|
|
||||||
send_json(Req, Status, Data) ->
|
send_json(Req, Status, Data) ->
|
||||||
|
Headers = #{
|
||||||
|
<<"content-type">> => <<"application/json">>,
|
||||||
|
<<"access-control-allow-origin">> => <<"*">>,
|
||||||
|
<<"access-control-expose-headers">> => <<"Content-Range">>
|
||||||
|
},
|
||||||
Body = jsx:encode(Data),
|
Body = jsx:encode(Data),
|
||||||
cowboy_req:reply(Status, #{<<"content-type">> => <<"application/json">>}, Body, Req),
|
cowboy_req:reply(Status, Headers, Body, Req),
|
||||||
{ok, Body, []}.
|
{ok, Body, []}.
|
||||||
|
|
||||||
send_error(Req, Status, Message) ->
|
send_error(Req, Status, Message) ->
|
||||||
|
|||||||
@@ -141,8 +141,13 @@ datetime_to_iso8601({{Year, Month, Day}, {Hour, Minute, Second}}) ->
|
|||||||
datetime_to_iso8601(undefined) -> undefined.
|
datetime_to_iso8601(undefined) -> undefined.
|
||||||
|
|
||||||
send_json(Req, Status, Data) ->
|
send_json(Req, Status, Data) ->
|
||||||
|
Headers = #{
|
||||||
|
<<"content-type">> => <<"application/json">>,
|
||||||
|
<<"access-control-allow-origin">> => <<"*">>,
|
||||||
|
<<"access-control-expose-headers">> => <<"Content-Range">>
|
||||||
|
},
|
||||||
Body = jsx:encode(Data),
|
Body = jsx:encode(Data),
|
||||||
cowboy_req:reply(Status, #{<<"content-type">> => <<"application/json">>}, Body, Req),
|
cowboy_req:reply(Status, Headers, Body, Req),
|
||||||
{ok, Body, []}.
|
{ok, Body, []}.
|
||||||
|
|
||||||
send_error(Req, Status, Message) ->
|
send_error(Req, Status, Message) ->
|
||||||
|
|||||||
@@ -31,8 +31,13 @@ auth_admin(Req) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
send_json(Req, Status, Data) ->
|
send_json(Req, Status, Data) ->
|
||||||
|
Headers = #{
|
||||||
|
<<"content-type">> => <<"application/json">>,
|
||||||
|
<<"access-control-allow-origin">> => <<"*">>,
|
||||||
|
<<"access-control-expose-headers">> => <<"Content-Range">>
|
||||||
|
},
|
||||||
Body = jsx:encode(Data),
|
Body = jsx:encode(Data),
|
||||||
cowboy_req:reply(Status, #{<<"content-type">> => <<"application/json">>}, Body, Req),
|
cowboy_req:reply(Status, Headers, Body, Req),
|
||||||
{ok, Body, []}.
|
{ok, Body, []}.
|
||||||
|
|
||||||
send_error(Req, Status, Message) ->
|
send_error(Req, Status, Message) ->
|
||||||
|
|||||||
@@ -141,8 +141,13 @@ datetime_to_iso8601({{Year, Month, Day}, {Hour, Minute, Second}}) ->
|
|||||||
datetime_to_iso8601(undefined) -> undefined.
|
datetime_to_iso8601(undefined) -> undefined.
|
||||||
|
|
||||||
send_json(Req, Status, Data) ->
|
send_json(Req, Status, Data) ->
|
||||||
|
Headers = #{
|
||||||
|
<<"content-type">> => <<"application/json">>,
|
||||||
|
<<"access-control-allow-origin">> => <<"*">>,
|
||||||
|
<<"access-control-expose-headers">> => <<"Content-Range">>
|
||||||
|
},
|
||||||
Body = jsx:encode(Data),
|
Body = jsx:encode(Data),
|
||||||
cowboy_req:reply(Status, #{<<"content-type">> => <<"application/json">>}, Body, Req),
|
cowboy_req:reply(Status, Headers, Body, Req),
|
||||||
{ok, Body, []}.
|
{ok, Body, []}.
|
||||||
|
|
||||||
send_error(Req, Status, Message) ->
|
send_error(Req, Status, Message) ->
|
||||||
|
|||||||
@@ -46,8 +46,13 @@ datetime_to_iso8601({{Y,M,D},{H,Min,S}}) ->
|
|||||||
datetime_to_iso8601(_) -> null.
|
datetime_to_iso8601(_) -> null.
|
||||||
|
|
||||||
send_json(Req, Status, Data) ->
|
send_json(Req, Status, Data) ->
|
||||||
|
Headers = #{
|
||||||
|
<<"content-type">> => <<"application/json">>,
|
||||||
|
<<"access-control-allow-origin">> => <<"*">>,
|
||||||
|
<<"access-control-expose-headers">> => <<"Content-Range">>
|
||||||
|
},
|
||||||
Body = jsx:encode(Data),
|
Body = jsx:encode(Data),
|
||||||
cowboy_req:reply(Status, #{<<"content-type">> => <<"application/json">>}, Body, Req),
|
cowboy_req:reply(Status, Headers, Body, Req),
|
||||||
{ok, Body, []}.
|
{ok, Body, []}.
|
||||||
|
|
||||||
send_error(Req, Status, Message) ->
|
send_error(Req, Status, Message) ->
|
||||||
|
|||||||
Reference in New Issue
Block a user