Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customize response #84

Closed
MarJose123 opened this issue Mar 19, 2021 · 4 comments
Closed

Customize response #84

MarJose123 opened this issue Mar 19, 2021 · 4 comments

Comments

@MarJose123
Copy link

Hi, it is possible to customize the error response to invalid signature? Instead of 500 I will customize it to 401, like for Xero accounting app.

@freekmurze
Copy link
Member

You could listen for the InvalidSignatureEvent and throw the exception you want there.

@kasperwandahl
Copy link

Hi @freekmurze I was just looking into this exact thing as a company I'm working with received the 500 Internal Server Error and pointed their fingers at me, when the issue was in their side not sending the signature. I think a 401 Unauthorized is a better response code as it's their input which fails to pass validation. Would you be willing to consider this change?

@freekmurze
Copy link
Member

Send a PR with tests, and I'll consider merging it in.

@mbroadhead
Copy link

@kasperwandahl @whoami213
You could also just override the rendering of the exception in app/Exceptions/Handler.php:

use Spatie\WebhookClient\Exceptions\WebhookFailed;
 
/**
 * Register the exception handling callbacks for the application.
 *
 * @return void
 */
public function register()
{
    $this->renderable(function (WebhookFailed $e, $request) {
         if ($request->is('api/*') && $e->getMessage() == 'The signature is invalid.') {
             return response()->json(['message' => $e->getMessage()], 401);
         }
    });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants