Služba padala při startu kvůli povinným SMSSLUZBA_LOGIN, SMSSLUZBA_PASSWORD a API_KEYS, proto v AppFactory nefungovalo /health ani /docs (502). - vlastní API klíče služby zrušeny, login a heslo API přístupu SMS-Služby posílá každá aplikace v hlavičkách X-Sms-Login a X-Sms-Password - všechna konfigurace je volitelná, neplatná hodnota jen zaloguje varování - po odmítnutí přihlášení se blokují jen ty konkrétní údaje - Swagger: Authorize pro obě hlavičky, relativní server i bez ROOT_PATH - návod pro napojení aplikací a dokumentace podle nového přihlášení
42 lines
1.5 KiB
C#
42 lines
1.5 KiB
C#
using SmsSluzba.Api.Gateway;
|
|
using SmsSluzba.Api.Problems;
|
|
|
|
namespace SmsSluzba.Api.Endpoints;
|
|
|
|
internal static class GatewayProblems
|
|
{
|
|
private const string UnknownStateDetail = "Stav není známý, brána mohla požadavek přijmout. Odeslání SMS neopakujte automaticky.";
|
|
|
|
public static ApiError ErrorFor(GatewayErrorKind kind) => kind switch
|
|
{
|
|
GatewayErrorKind.InvalidRecipient => ApiErrors.InvalidRecipient,
|
|
GatewayErrorKind.MissingText => ApiErrors.MissingText,
|
|
GatewayErrorKind.Rejected => ApiErrors.ProviderRejected,
|
|
GatewayErrorKind.AuthFailed or GatewayErrorKind.AuthBlocked => ApiErrors.InvalidCredentials,
|
|
GatewayErrorKind.InsufficientCredit => ApiErrors.InsufficientCredit,
|
|
GatewayErrorKind.Timeout => ApiErrors.ProviderTimeout,
|
|
_ => ApiErrors.ProviderUnavailable,
|
|
};
|
|
|
|
public static IResult ToResult(GatewayException ex)
|
|
{
|
|
var error = ErrorFor(ex.Kind);
|
|
var detail = ex.ProviderMessage ?? (error.Status is 502 or 504 ? UnknownStateDetail : null);
|
|
return ApiProblems.Result(error, detail, ex.ProviderCode);
|
|
}
|
|
|
|
/// <summary>Runs a gateway call and turns a gateway failure into a problem response.</summary>
|
|
public static async Task<IResult> RunAsync(Func<Task<IResult>> call)
|
|
{
|
|
try
|
|
{
|
|
return await call();
|
|
}
|
|
catch (GatewayException ex)
|
|
{
|
|
// Already logged by SmsGatewayClient.
|
|
return ToResult(ex);
|
|
}
|
|
}
|
|
}
|