@@ -55,52 +55,47 @@ ClaimValidator *ClaimValidatorFactory::BuildInternal(const json &json) {
55
55
}
56
56
57
57
ClaimValidator *constructed = nullptr ;
58
- if (json.count (" iss" )) {
59
- constructed = new ListClaimValidator (" iss" , BuildList (json[" iss" ]));
60
- } else if (json.count (" sub" )) {
61
- constructed = new ListClaimValidator (" sub" , BuildList (json[" sub" ]));
62
- } else if (json.count (" aud" )) {
63
- constructed = new ListClaimValidator (" aud" , BuildList (json[" aud" ]));
64
- } else if (json.count (" exp" )) {
65
- ::json val = json[" exp" ];
66
- ::json leeway = val[" leeway" ];
67
- constructed =
68
- new ExpValidator (leeway.is_null () ? 0 : leeway.get <int >());
69
- } else if (json.count (" nbf" )) {
70
- ::json val = json[" nbf" ];
71
- ::json leeway = val[" leeway" ];
72
- constructed =
73
- new NbfValidator (leeway.is_null () ? 0 : leeway.get <int >());
74
- } else if (json.count (" iat" )) {
75
- ::json val = json[" iat" ];
76
- ::json leeway = val[" leeway" ];
77
- constructed =
78
- new IatValidator (leeway.is_null () ? 0 : leeway.get <int >());
79
- }
80
-
81
58
try {
82
- if (json.count (" all" )) {
59
+ if (json.count (" iss" )) {
60
+ constructed = new ListClaimValidator (" iss" , BuildList (json[" iss" ]));
61
+ } else if (json.count (" sub" )) {
62
+ constructed = new ListClaimValidator (" sub" , BuildList (json[" sub" ]));
63
+ } else if (json.count (" aud" )) {
64
+ constructed = new ListClaimValidator (" aud" , BuildList (json[" aud" ]));
65
+ } else if (json.count (" exp" )) {
66
+ ::json val = json[" exp" ];
67
+ ::json leeway = val[" leeway" ];
68
+ constructed =
69
+ new ExpValidator (leeway.is_null () ? 0 : leeway.get <int >());
70
+ } else if (json.count (" nbf" )) {
71
+ ::json val = json[" nbf" ];
72
+ ::json leeway = val[" leeway" ];
73
+ constructed =
74
+ new NbfValidator (leeway.is_null () ? 0 : leeway.get <int >());
75
+ } else if (json.count (" iat" )) {
76
+ ::json val = json[" iat" ];
77
+ ::json leeway = val[" leeway" ];
78
+ constructed =
79
+ new IatValidator (leeway.is_null () ? 0 : leeway.get <int >());
80
+ } else if (json.count (" all" )) {
83
81
constructed =
84
82
new AllClaimValidator (BuildValidatorList (json[" all" ]));
85
83
} else if (json.count (" any" )) {
86
84
constructed =
87
85
new AnyClaimValidator (BuildValidatorList (json[" any" ]));
88
86
} else if (json.count (" optional" )) {
89
- ::json val = json[" optional" ];
90
- ClaimValidator *inner = Build (val);
87
+ ClaimValidator *inner = BuildInternal (json[" optional" ]);
91
88
constructed = new OptionalClaimValidator (inner);
92
89
}
93
90
} catch (std::exception &le) {
94
- std::ostringstream msg;
95
- msg << " Json error inside: " << le.what ();
96
- msg << " , at: " << json;
97
- throw std::logic_error (msg.str ());
91
+ throw std::logic_error (
92
+ std::string (" Failed to construct validator at: " ) + json.dump () +
93
+ " , " + le.what ());
98
94
}
99
95
100
96
if (!constructed) {
101
- std::ostringstream msg;
102
- msg << " Missing property at: " << json;
103
- throw std::logic_error (msg.str ());
97
+ throw std::logic_error (std::string (" No validator declared at: " ) +
98
+ json.dump ());
104
99
}
105
100
106
101
build_.push_back (constructed);
0 commit comments