Describe the bug
Saving a bad type of credentials fails silently (response is 200
with error message in it)
Package concerned
@bearer/js
To Reproduce
Steps to reproduce the behavior.
- Sign in to your Bearer dashboard
- Make sure you've the Stripe API added
- Serve the following code
<!DOCTYPE html>
<script src="https://cdn.jsdelivr.net/npm/@bearer/js/lib/bearer.production.min.js"></script>
<script>
const bearerClient = bearer('YOUR-PUBLISHABLE-KEY')
bearerClient
.integration('stripe')
.invoke('bearer-setup-save', { setup: { type: 'TEST', apiKey: 'stripe-api-key' } })
.then(({ data }) => console.log(data.setupId))
</script>
- Look into the network tab of your web DevTools. The request to save credentials returns a
200
.
Expected behavior
The authentication type passed is TEST
, which isn't supported by Bearer. So I presume Bearer should reply with a 400 Bad request
.
The error message in the response is pretty helpful though:
{
"error":{
"isJoi":true,
"name":"ValidationError",
"details":[
{
"message":"\"type\" must be one of [OAUTH2, OAUTH1, APIKEY, BASIC]",
"path":["type"],
"type":"any.allowOnly",
"context":{
"value":"TEST",
"valids":[ "OAUTH2", "OAUTH1", "APIKEY", "BASIC" ],
"key":"type",
"label":"type"
}
}
],
"_object":{
"type":"TEST",
"apiKey":"stripe-api-key"
}
}
}
```