mjashanks / budibase-core

Mozilla Public License 2.0
4 stars 2 forks source link

Attach HTTP Status code to exceptions where relevant #8

Closed mjashanks closed 5 years ago

mjashanks commented 5 years ago

The webserver consumes budibase-core. Currently, when an exception occurs in budibase-core, it will always manifest as a 500 Internal Server Error.

There are a few cases where we can give a better status

I suggest that we implement this as follows:

//  common/errors.js
export const ForbiddenError = (message) => {
    const err = new Error(message);
    err.HttpStatus = 403;
    return err
}

// somwehere where exception is being thrown
throw ForbiddenError("Not authorized to create Customer record");

404s may be difficult, as these may often be raised by the datastore implementation (which is plugged in and not part of budibase-core. e.g node "fs" may throw "File not found /customers/1-abcd/record.json"

... or this could just be a matter of applying this logic inside that datastores also... proabbly makes sense.

danbudi commented 5 years ago

Hi i have started this.

danbudi commented 5 years ago

Can close this