cjmling / findings

Notes on stuff i finds worth keeping for quick reference later on.
2 stars 0 forks source link

FR: return json error response and throwing exception in lumen #90

Open cjmling opened 5 years ago

cjmling commented 5 years ago

Instead of

return $this->response()->json([
    'errors' => 'Whoops, looks like something went wrong. Try again later or',
         'debug' => 'Unable to create temporary ban',
], 400);

we can do

throw new \Exception('Unable to create temporary ban');

cjmling commented 5 years ago

Instead of

if (!$result) {
    return $this->response()->json([
            'errors' => 'This is shown to user',
    ], 400);
}

we can do

if (!$result) {
    throw new FootyRoom\Core\CoreException('This is shown to user');
}
cjmling commented 5 years ago

basically CoreException(‘message’) if you want user to see the error message instead of “Whooops…” and any other type of Exception(‘private message’) if you want only developers to see the message but everyone else gets “Whoops…”

error handler should take care of json response if route was called with ajax