API version2 update

Added get tcket lists master API

update
This commit is contained in:
Manish Verma
2018-08-23 15:32:59 +05:30
committed by Manish Verma
parent 8e006192b1
commit 8f4a43a723
3 changed files with 154 additions and 0 deletions

View File

@@ -222,3 +222,42 @@ function timezone()
return $tz;
}
// For API response
/**
* formats the error message into json error response
* @param string/array $errorMsg errorMsg can be an array of errors or string
* @param integer $responseCode
* @return json
*/
function errorResponse($errorMsg, $responseCode = 400){
$response = ['success'=>false, 'message'=>$errorMsg];
return response()->json($response, $responseCode);
}
/**
* formats success message/data into json success response
* @param string $successMsg
* @param array/string $data data of the response
* @param integer $responseCode
* @return json
*/
function successResponse($successMsg='', $data='', $responseCode=200){
$response = !$successMsg ? ['success'=>true, 'data'=>$data] : (!$data ? ['success'=>true, 'message'=>$successMsg] : ['success'=>true, 'message'=>$successMsg, 'data'=>$data]);
return response()->json($response);
}
/**
* formats exception response by giving enough information for debugginh
* @param \Exception $exception exception object
* @return Response with json response content
*/
function exceptionResponse(\Exception $exception){
return errorResponse([
'file'=>$exception->getFile(),
'line_number'=>$exception->getLine(),
'exception'=>$exception->getMessage(),
], 500);
}