Implement micropub update support with clean exception-based error handling
- Add MicropubUnsupportedModelException for non-note update attempts - Refactor UpdateHandler to throw exceptions instead of returning JsonResponse objects; extract applySyndication() to DRY up duplicated syndication URL mapping - Fix MicropubController: InvalidTokenScopeException now returns 401 + insufficient_scope; add catches for ModelNotFoundException (404) and MicropubUnsupportedModelException (500); updates return 200 not 201 - Slim MicropubRequest.normalizeMicropubJson() to branch on action type, keeping update and create fields cleanly separated - Update tests to match corrected status codes and error keys; remove markTestSkipped() from all update tests Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
a342b432d4
commit
24cb6d61aa
6 changed files with 93 additions and 95 deletions
|
|
@ -48,20 +48,25 @@ class MicropubRequest extends FormRequest
|
|||
|
||||
$data = $json->all();
|
||||
|
||||
// Convert JSON type (h-entry) to simple type (entry)
|
||||
$this->micropubData['token_data'] = $data['token_data'];
|
||||
|
||||
if (isset($data['action']) && $data['action'] === 'update') {
|
||||
$this->micropubData['type'] = 'update';
|
||||
$this->micropubData['update_url'] = $data['url'] ?? null;
|
||||
$this->micropubData['update_replace'] = $data['replace'] ?? null;
|
||||
$this->micropubData['update_add'] = $data['add'] ?? null;
|
||||
$this->micropubData['update_delete'] = $data['delete'] ?? null;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Create request — normalize h-type and properties
|
||||
if (isset($data['type']) && is_array($data['type'])) {
|
||||
$type = current($data['type']);
|
||||
if (str_starts_with($type, 'h-')) {
|
||||
$this->micropubData['type'] = substr($type, 2);
|
||||
}
|
||||
}
|
||||
// Or set the type to update
|
||||
elseif (isset($data['action']) && $data['action'] === 'update') {
|
||||
$this->micropubData['type'] = 'update';
|
||||
}
|
||||
|
||||
// Add in the token data
|
||||
$this->micropubData['token_data'] = $data['token_data'];
|
||||
|
||||
// Add h-entry values
|
||||
$this->micropubData['content'] = Arr::get($data, 'properties.content.0');
|
||||
|
|
|
|||
Loading…
Reference in a new issue