samedi 29 décembre 2018

what is the recommended way to check error in rest api? [duplicate]

We are building Rest API, but we're not able to decide how we should show the errors, what is more common and easy to use.

1)

$request = class->function();
try{
//success
}catch(Exception $e){
echo $e->getMessage();
}

vs

$request = class->function();
if($request['status']){
//success
}else{
echo $request['error']['message'];
}

2) If we decide to go with if/else then which key is more common, and easy to use? $request['status'] or $request['state'] or something you can recommend.

We also looked for best practices of designing API but none of them mentioned this case.

Aucun commentaire:

Enregistrer un commentaire