Add ValidationException and throw it when signRequest() or verifyRequest() fail validation.
WHY?
When there's a validation error a runtypes.ValidationError is thrown. This is an internal implementation detail and as such, there is no supported way of detecting validation errors.
import { ValidationException, verifyRequest } from '@contentful/node-apps-toolkit'
try {
verifyRequest(/* ...*/)
} catch (e) {
if (e instanceof ValidationException) {
if (e.constraintName === 'SecretLength') {
// this is unexpected, return 500 status code and alarm
} else {
// this is expected, should return 400 or 403 status code
}
}
}
WHAT?
Add
ValidationException
and throw it whensignRequest()
orverifyRequest()
fail validation.WHY?
When there's a validation error a
runtypes.ValidationError
is thrown. This is an internal implementation detail and as such, there is no supported way of detecting validation errors.Similar to #692, so that developers can: