Handling Exceptions

The following guide shows you how to handle OneSpan Sign exceptions.

The following are two exception types in OneSpan Sign:

  • EslException: This is a general exception. It includes a character string that indicates what failed.
  • EslServerException: This is a subclass of EslException. An EslServerException is thrown when the server returns unexpected code from a request. The EslServerException also contains the exact server response from the underlying API request.

The Code

The following code sample illustrates how to differentiate between the two exception types and how to gain access to the underlying server response if an EslServerException is thrown:

try {
      signer = signerBuilder.build();
} catch( EslException eslException ) {
      System.out.println( eslException.getLocalizedMessage() );
      return;
}

try {
     eslClient.getPackageService().addSigner( new PackageId( "myPackageId" ), signer);
} catch( EslServerException eslServerException ) {
      // The request was refused by the server for some reason...
      System.out.println(eslServerException.getLocalizedMessage());
      System.out.println(eslServerException.getServerError().getCode());
      System.out.println(eslServerException.getServerError().getMessage());
      System.out.println(eslServerException.getServerError().getTechnical());
      return;
} catch( EslException eslException ) {
      System.out.println( eslException.getLocalizedMessage() );
      return;
}

Running Your Code

Get the Code

The following are two exception types in OneSpan Sign:

  • EslException: This is a general exception. It includes a character string that indicates what failed.
  • EslServerException: This is a subclass of EslException. An EslServerException is thrown when the server returns unexpected code from a request. The EslServerException also contains the exact server response from the underlying API request.

The Code

The following code sample illustrates how to differentiate between the two exception types and how to gain access to the underlying server response if an EslServerException is thrown:

try
{
    signer = signerBuilder.Build();
}
catch (EslException eslException)
{
     Console.Out.WriteLine(eslException.Message);
     return;
}

try
{
     eslClient.PackageService.AddSigner(new PackageId("myPackageId"),signer);                                
}
catch (EslServerException eslServerException)
{
      Console.Out.WriteLine(eslServerException.Message);
      Console.Out.WriteLine(eslServerException.ServerError.Code);
      Console.Out.WriteLine(eslServerException.ServerError.Message);
      Console.Out.WriteLine(eslServerException.ServerError.Technical);
 }
catch (EslException eslException)
{
      Console.Out.WriteLine(eslException.Message);
      return;
}

Running Your Code

Get the Code