1818import jakarta .enterprise .context .ApplicationScoped ;
1919import jakarta .enterprise .inject .Produces ;
2020import jakarta .inject .Inject ;
21- import java .util .Arrays ;
22- import java .util .Objects ;
2321import org .eclipse .microprofile .config .inject .ConfigProperty ;
2422import org .jspecify .annotations .NonNull ;
2523
@@ -38,31 +36,36 @@ public class ClientProvider {
3836 private String network ;
3937
4038 private AccountId getAccountId () {
39+ if (network == null ) {
40+ throw new IllegalStateException ("accountId value is null" );
41+ }
4142 try {
4243 return AccountId .fromString (accountIdAsString );
4344 } catch (Exception e ) {
44- throw new IllegalArgumentException ("Can not parse 'hedera.newAccountId' property" , e );
45+ throw new IllegalArgumentException (
46+ "Can not parse 'hedera.newAccountId' property: '" + accountIdAsString + "'" , e );
4547 }
4648 }
4749
4850 private PrivateKey getPrivateKey () {
51+ if (network == null ) {
52+ throw new IllegalStateException ("privateKey value is null" );
53+ }
4954 try {
5055 return PrivateKey .fromString (privateKeyAsString );
5156 } catch (Exception e ) {
52- throw new IllegalArgumentException ("Can not parse 'hedera.privateKey' property" , e );
57+ throw new IllegalArgumentException (
58+ "Can not parse 'hedera.privateKey' property: '" + privateKeyAsString + "'" , e );
5359 }
5460 }
5561
5662 private HederaNetwork getHederaNetwork () {
57- if (Arrays .stream (HederaNetwork .values ()).anyMatch (v -> Objects .equals (v .getName (), network ))) {
58- try {
59- return HederaNetwork .valueOf (network .toUpperCase ());
60- } catch (Exception e ) {
61- throw new IllegalArgumentException ("Can not parse 'hedera.network' property" , e );
62- }
63- } else {
64- throw new IllegalArgumentException ("'hedera.network' property must be set to a valid value" );
63+ if (network == null ) {
64+ throw new IllegalStateException ("network value is null" );
6565 }
66+ return HederaNetwork .findByName (network )
67+ .orElseThrow (() -> new IllegalArgumentException (
68+ "'hedera.network' property must be set to a valid value. Is '" + network + "'" ));
6669 }
6770
6871 private Client createClient () {
0 commit comments