Created timestamper_dev module, logging.
This commit is contained in:
@ -21,8 +21,8 @@ out(YArg) ->
|
||||
case catch dispatch_request(YArg, Session, PathElements) of
|
||||
{'EXIT', Err} ->
|
||||
% TODO: log error internally
|
||||
io:format("~p", [Err]),
|
||||
make_json_500(YArg);
|
||||
error_logger:error_report("TimeStamper: ~p", [Err]),
|
||||
make_json_500(YArg, Err);
|
||||
Other -> Other
|
||||
end.
|
||||
|
||||
@ -306,7 +306,9 @@ put_timeline(YArg, Username, TimelineId) ->
|
||||
|
||||
{content, "application/json", JSONResponse};
|
||||
|
||||
_Error -> make_json_500(YArg)
|
||||
Error ->
|
||||
error_logger:error_report("Unable to create a new timeline: ~p", [Error]),
|
||||
make_json_500(YArg, Error)
|
||||
end.
|
||||
|
||||
post_timeline(YArg, Username, TimelineId) ->
|
||||
@ -333,7 +335,9 @@ post_timeline(YArg, Username, TimelineId) ->
|
||||
[{status, "no such timeline"},
|
||||
{see_docs, "/ts_api_doc/timelines.html#POST"}]);
|
||||
|
||||
_Error -> make_json_500(YArg)
|
||||
Error ->
|
||||
error_logger:error_report("Unable update timeline: ~p", [Error]),
|
||||
make_json_500(YArg, Error)
|
||||
end.
|
||||
|
||||
delete_timeline(_YArg, _Username, _TimelineId) -> {status, 405}.
|
||||
@ -458,8 +462,8 @@ put_entry(YArg, Username, TimelineId) ->
|
||||
{content, "application/json", JSONResponse};
|
||||
|
||||
OtherError ->
|
||||
io:format("Could not create entry: ~p", [OtherError]),
|
||||
make_json_500(YArg)
|
||||
error_logger:error_report("TimeStamper: Could not create entry: ~p", [OtherError]),
|
||||
make_json_500(YArg, OtherError)
|
||||
end.
|
||||
|
||||
post_entry(YArg, Username, TimelineId, EntryId) ->
|
||||
@ -479,7 +483,9 @@ post_entry(YArg, Username, TimelineId, EntryId) ->
|
||||
no_record -> make_json_404(YArg,
|
||||
[{status, "no such entry"}, {see_docs, "/ts_api_doc/entries.html#POST"}]);
|
||||
|
||||
_Error -> make_json_500(YArg)
|
||||
Error ->
|
||||
error_logger:error_report("TimeStamper: Unable to update entry: ~p", [Error]),
|
||||
make_json_500(YArg, Error)
|
||||
end.
|
||||
|
||||
delete_entry(YArg, Username, TimelineId, EntryId) ->
|
||||
@ -494,8 +500,8 @@ delete_entry(YArg, Username, TimelineId, EntryId) ->
|
||||
case ts_entry:delete(Record) of
|
||||
ok -> {status, 200};
|
||||
Error ->
|
||||
io:format("Error occurred deleting entry record: ~p", [Error]),
|
||||
make_json_500(YArg)
|
||||
error_logger:error_report("Error occurred deleting entry record: ~p", [Error]),
|
||||
make_json_500(YArg, Error)
|
||||
end
|
||||
end.
|
||||
|
||||
@ -512,7 +518,7 @@ parse_json_body(YArg) ->
|
||||
{done, {ok, EJSON}, _} -> EJSON;
|
||||
Error ->
|
||||
% TODO: log error internally
|
||||
io:format("~p", [Error]),
|
||||
error_logger:error_report("Error parsing JSON request body: ~p", [Error]),
|
||||
throw(make_json_400(YArg))
|
||||
end.
|
||||
|
||||
@ -577,6 +583,12 @@ make_json_405(YArg, Fields) ->
|
||||
|
||||
[{status, 405}, {content, "application/json", json:encode({struct, F2})}].
|
||||
|
||||
make_json_500(_YArg, Error) ->
|
||||
EJSON = {struct, [
|
||||
{status, "internal server error"},
|
||||
{error, io_lib:format("~p", [Error])}]},
|
||||
[{status, 500}, {content, "application/json", json:encode(EJSON)}].
|
||||
|
||||
make_json_500(_YArg) ->
|
||||
EJSON = {struct, [
|
||||
{status, "internal server error"}]},
|
||||
|
Reference in New Issue
Block a user