jaystack / odata-v4-server

With JayStack OData v4 Server you can build your own data endpoints without the hassle of implementing any protocol-level code. This framework binds OData v4 requests to your annotated controller functions, and compiles OData v4 compatible response. Clients can access services through OData-compliant HTTP requests. We recommend the JayData library for consuming OData v4 APIs.
https://jaystack.com/products/jaystack-odata-v4-server/
76 stars 55 forks source link

How to disable "stack trace" in errors outputs? #18

Closed mindonline closed 6 years ago

mindonline commented 7 years ago

How to disable this output due to security issues on raised errors like 404 ? I didn't saw any ways to overcome ODataErrorHandler behavior.

mindonline commented 7 years ago

Please, consider pull request. #19 Also, may be some one helps, as intermediate solution I found this:

// Custom error handler
function ODataErrorHandler(err, _, res, next){
    .....
}

/// YOUR DECORATORS HERE
export class NorthwindServer extends ODataServer{
    ....
    static oldRequestHandlerRes;

    static requestHandler(){
        this.oldRequestHandlerRes = super.requestHandler();     
        return (req:express.Request, res:express.Response, next:express.NextFunction) => {
            return next();
        }
    }
}

const app = express();
app.use(
    NorthwindServer.create(),
    NorthwindServer.oldRequestHandlerRes,
    ODataErrorHandler
);
app.listen(3000);
lazarv commented 6 years ago

Hi @mindonline, using odata-v4-server@0.2.11 you can define custom error request handler, see example here: https://github.com/jaystack/odata-v4-server/blob/master/src/example/advanced.ts#L84 and you can define the ODATA_V4_DISABLE_STACKTRACE environment variable to disable stacktrace using the default ODataErrorHandler.