Skip to content

Commit

Permalink
Merge pull request #83 from Bdaya-Dev/fix/facade-error-handling
Browse files Browse the repository at this point in the history
fix: improve OidcEndpoints error handling
  • Loading branch information
ahmednfwela authored Jun 8, 2024
2 parents 44a67c8 + 717d533 commit 0128f08
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/oidc/test/mock_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Future<Response> _handleRequest(
final url = request.url;

if (_eq.equals(url.pathSegments, ['.well-known', 'openid-configuration'])) {
return Response(jsonEncode(mockProviderMetadata), 304);
return Response(jsonEncode(mockProviderMetadata), 200);
}
if (url.pathSegments.first == 'token') {
final tokenResp = createMockTokenResponse(
Expand Down
8 changes: 8 additions & 0 deletions packages/oidc_core/lib/src/endpoints/facade.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class OidcEndpoints {
}) {
try {
final body = jsonDecode(response.body) as Map<String, dynamic>;

if (body.containsKey(OidcConstants_AuthParameters.error)) {
final resp = OidcErrorResponse.fromJson(body);
throw OidcException.serverError(
Expand All @@ -28,6 +29,13 @@ class OidcEndpoints {
rawResponse: response,
);
}
if (!(response.statusCode >= 200 && response.statusCode < 400)) {
throw OidcException(
'Failed to handle the response from endpoint (status code ${response.statusCode}): ${request.url}',
rawRequest: request,
rawResponse: response,
);
}
return mapper(body);
} on OidcException {
rethrow;
Expand Down

0 comments on commit 0128f08

Please sign in to comment.