ballerina-platform / ballerina-library

The Ballerina Library
https://ballerina.io/learn/api-docs/ballerina/
Apache License 2.0
136 stars 64 forks source link

Internal Auth Errors should not be Logged as Unhandled Error #7395

Open DimuthuMadushan opened 3 days ago

DimuthuMadushan commented 3 days ago

Description

$subject

Currently, the service logged an unhandled error message for request with invalid credentials.

Steps to Reproduce

consider the following service with basic auth.

import ballerina/http;

type Album readonly & record {|
    string title;
    string artist;
|};

listener http:Listener securedEP = new (9090);

@http:ServiceConfig {
    auth: [
        {
            fileUserStoreConfig: {},
            scopes: ["admin"]
        }
    ]
}
service / on securedEP {

    resource function get albums() returns Album[] {
        return [
            {title: "Blue Train", artist: "John Coltrane"},
            {title: "Jeru", artist: "Gerry Mulligan"}
        ];
    }
}

When we send request with invalid credentials, it logs the following message.

curl --location --request GET 'http://localhost:9090/albums' \
--header 'Authorization: Basic YWxpYzphbGljZUAxMjM='

error message:

Running executable

error: 
        at ballerina.http.2:authenticateResource(auth_desugar.bal:45)
           dimuthu.basic_auth.0.$anonType$_1:$get$albums(service.bal:54)
time=2024-11-21T14:24:42.408+05:30 level=ERROR module=ballerina/http message="unhandled error returned from the service" error={"causes":[],"message":"","detail":{},"stackTrace":[{"callableName":"authenticateResource","moduleName":"ballerina.http.2","fileName":"auth_desugar.bal","lineNumber":45},{"callableName":"$get$albums","moduleName":"dimuthu.basic_auth.0.$anonType$_1","fileName":"service.bal","lineNumber":54}]} path="/albums" method="GET"

Version

2201.8.8, 2201.10.0

Environment Details (with versions)

No response

TharmiganK commented 3 days ago

The first error log is expected:

error: 
        at ballerina.http.2:authenticateResource(auth_desugar.bal:45)
           dimuthu.basic_auth.0.$anonType$_1:$get$albums(service.bal:54)

The second log is not required since it is an internal error