scaphold-io / scaphold-issues

Post issues that you find on Scaphold here. Post anything about the platform, docs, boilerplates, etc... Happy Scapholding!
3 stars 0 forks source link

Let prehooks return clean errors #21

Open martinheidegger opened 7 years ago

martinheidegger commented 7 years ago

Currently the only way I can see pre-hooks (logic) to prevent continued processing is by returning a non-200 error code. However this will result in a ugly error messages shown in the client of the user. It would be nice to have a way to cleanly return error messages (i.e. with validation errors)

mikeparisstuff commented 7 years ago

Can you give an example of what a clean error message would look like from the client perspective?

martinheidegger commented 7 years ago

A lamda function like this:

callback(null, {
    statusCode: 200,
    body: JSON.stringify({
        errors: [
            'phoneNumber is not a valid phoneNumber'
        ]
    })
})

stops the execution and shows different outputs depending if I am logged-in as admin user or regularily:

Regular: {errors: ['phoneNumber is not a valid phoneNumber'] Logged-in:

{
  errors: ['phoneNumber is not a valid phoneNumber'],
  errorLocation: 'pre-hook-0'
}

for debugging.