Much better json response code, add an extra try/catch
This commit is contained in:
parent
0d1787d69a
commit
3c689c09ed
1 changed files with 23 additions and 38 deletions
|
@ -57,17 +57,15 @@ class MicropubController extends Controller
|
|||
if (array_search('post', $scopes) !== false) {
|
||||
$clientId = $tokenData->getClaim('client_id');
|
||||
if (($request->input('h') == 'entry') || ($request->input('type')[0] == 'h-entry')) {
|
||||
$note = $this->noteService->createNote($request, $clientId);
|
||||
$content = <<<EOD
|
||||
{
|
||||
"response": "created",
|
||||
"location": "$note->longurl"
|
||||
}
|
||||
EOD;
|
||||
|
||||
return (new Response($content, 201))
|
||||
->header('Location', $note->longurl)
|
||||
->header('Content-Type', 'application/json');
|
||||
try {
|
||||
$note = $this->noteService->createNote($request, $clientId);
|
||||
} catch (Exception $exception) {
|
||||
return response()->json(['error' => true], 400);
|
||||
}
|
||||
return response()->json([
|
||||
'response' => 'created',
|
||||
'location' => $note->longurl
|
||||
], 201)->header('Location', $note->longurl);
|
||||
}
|
||||
if ($request->input('h') == 'card' || $request->input('type')[0] == 'h-card') {
|
||||
try {
|
||||
|
@ -75,40 +73,27 @@ EOD;
|
|||
} catch (Exception $exception) {
|
||||
return response()->json(['error' => true], 400);
|
||||
}
|
||||
$content = <<<EOD
|
||||
{
|
||||
"response": "created",
|
||||
"location": "$place->longurl"
|
||||
}
|
||||
EOD;
|
||||
|
||||
return (new Response($content, 201))
|
||||
->header('Location', $place->longurl)
|
||||
->header('Content-Type', 'application/json');
|
||||
return response()->json([
|
||||
'response' => 'created',
|
||||
'location' => $place->longurl
|
||||
], 201)->header('Location', $place->longurl);
|
||||
}
|
||||
}
|
||||
}
|
||||
$content = <<<'EOD'
|
||||
{
|
||||
"response": "error",
|
||||
"error": "invalid_token",
|
||||
"error_description": "The token provided is not valid or does not have the necessary scope",
|
||||
}
|
||||
EOD;
|
||||
|
||||
return (new Response($content, 400))
|
||||
->header('Content-Type', 'application/json');
|
||||
return response()->json([
|
||||
'response' => 'error',
|
||||
'error' => 'invalid_token',
|
||||
'error_description' => 'The token provided is not valid or does not have the necessary scope'
|
||||
], 400);
|
||||
}
|
||||
$content = <<<'EOD'
|
||||
{
|
||||
"response": "error",
|
||||
"error": "no_token",
|
||||
"error_description": "No OAuth token sent with request"
|
||||
}
|
||||
EOD;
|
||||
|
||||
return (new Response($content, 400))
|
||||
->header('Content-Type', 'application/json');
|
||||
return response()->json([
|
||||
'response' => 'error',
|
||||
'error' => 'no_token',
|
||||
'error_description' => 'No OAuth token sent with request'
|
||||
], 400);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue