fix: try-catch for unknow reason to inhibit api crash
This commit is contained in:
parent
042a84c30f
commit
812e8ef314
|
@ -883,15 +883,33 @@ gen_point(Type, Name, Path) ->
|
||||||
%% TODO: cert manager for more generic utils functions
|
%% TODO: cert manager for more generic utils functions
|
||||||
cert_expiry_at_from_path(Path0) ->
|
cert_expiry_at_from_path(Path0) ->
|
||||||
Path = emqx_schema:naive_env_interpolation(Path0),
|
Path = emqx_schema:naive_env_interpolation(Path0),
|
||||||
case file:read_file(Path) of
|
try
|
||||||
{ok, PemBin} ->
|
case file:read_file(Path) of
|
||||||
[CertEntry | _] = public_key:pem_decode(PemBin),
|
{ok, PemBin} ->
|
||||||
Cert = public_key:pem_entry_decode(CertEntry),
|
[CertEntry | _] = public_key:pem_decode(PemBin),
|
||||||
%% TODO: Not fully tested for all certs type
|
Cert = public_key:pem_entry_decode(CertEntry),
|
||||||
{'utcTime', NotAfterUtc} =
|
%% TODO: Not fully tested for all certs type
|
||||||
Cert#'Certificate'.'tbsCertificate'#'TBSCertificate'.validity#'Validity'.'notAfter',
|
{'utcTime', NotAfterUtc} =
|
||||||
utc_time_to_epoch(NotAfterUtc);
|
Cert#'Certificate'.'tbsCertificate'#'TBSCertificate'.validity#'Validity'.'notAfter',
|
||||||
{error, _} ->
|
utc_time_to_epoch(NotAfterUtc);
|
||||||
|
{error, Reason} ->
|
||||||
|
?SLOG(error, #{
|
||||||
|
msg => "read_cert_file_failed",
|
||||||
|
path => Path0,
|
||||||
|
resolved_path => Path,
|
||||||
|
reason => Reason
|
||||||
|
}),
|
||||||
|
0
|
||||||
|
end
|
||||||
|
catch
|
||||||
|
E:R ->
|
||||||
|
?SLOG(error, #{
|
||||||
|
msg => "obtain_cert_expiry_time_failed",
|
||||||
|
error => E,
|
||||||
|
reason => R,
|
||||||
|
path => Path0,
|
||||||
|
resolved_path => Path
|
||||||
|
}),
|
||||||
0
|
0
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue