laravel-responder icon indicating copy to clipboard operation
laravel-responder copied to clipboard

How do I customize error code when using responder()->error()->respond?

Open aligajani opened this issue 4 years ago • 1 comments

Hey dude, great package. Would love to customize the error code when doing:

responder()->error('email_taken', 'The email is already taken')->respond();

so it doesn't always return error=500 by default. Also, not ideal to create an exception.

{"status":500,"success":false,"error":{"code":"email_taken","message":"The email is already taken"}}

Surely there is a simpler way. Any tips?

aligajani avatar Jan 16 '20 01:01 aligajani

you can specify the error code like ->respond(400)

Hesesses avatar Jan 16 '20 12:01 Hesesses