diff options
author | Aaron Parecki <aaron@parecki.com> | 2017-02-27 12:38:02 -0800 |
---|---|---|
committer | Aaron Parecki <aaron@parecki.com> | 2017-02-27 12:38:02 -0800 |
commit | 793199ad4efd02f3e95e7fbb0f5af6ee7833b844 (patch) | |
tree | dde2020209339ed93afe1dcfe9a4d2219e1b89bc | |
parent | 1123ed958f7c22116a0c432779aaf1c27fcaf787 (diff) |
show error messages when editing favorites
-rw-r--r-- | controllers/controllers.php | 14 | ||||
-rw-r--r-- | views/new-favorite.php | 7 |
2 files changed, 17 insertions, 4 deletions
diff --git a/controllers/controllers.php b/controllers/controllers.php index 215b932..90c229a 100644 --- a/controllers/controllers.php +++ b/controllers/controllers.php @@ -441,12 +441,21 @@ $app->post('/favorite', function() use($app) { if($user=require_login($app)) { $params = $app->request()->params(); + $error = false; + if(isset($params['edit'])) { $r = edit_favorite($user, $params['edit'], $params['like_of']); if(isset($r['location']) && $r['location']) $location = $r['location']; - else + elseif(in_array($r['code'], [200,201,204])) $location = $params['edit']; + elseif(in_array($r['code'], [401,403])) { + $location = false; + $error = 'Your Micropub endpoint denied the request. Check that Quill is authorized to update posts.'; + } else { + $location = false; + $error = 'Your Micropub endpoint did not return a location header or a recognized response code'; + } } else { $r = create_favorite($user, $params['like_of']); $location = $r['location']; @@ -455,7 +464,8 @@ $app->post('/favorite', function() use($app) { $app->response()['Content-type'] = 'application/json'; $app->response()->body(json_encode(array( 'location' => $location, - 'error' => $r['error'] + 'error' => $r['error'], + 'error_details' => $error, ))); } }); diff --git a/views/new-favorite.php b/views/new-favorite.php index 524bb79..72de412 100644 --- a/views/new-favorite.php +++ b/views/new-favorite.php @@ -32,7 +32,7 @@ $(function(){ $("#btn_post").click(function(){ - $("#btn_post").addClass("loading disabled").text("Working..."); + $("#btn_post").addClass("loading disabled"); var syndications = []; $("#syndication-container button.btn-info").each(function(i,btn){ @@ -53,7 +53,10 @@ $(function(){ } else { $("#test_success").addClass('hidden'); $("#test_error").removeClass('hidden'); - $("#btn_post").removeClass("loading disabled").text("Post"); + if(response.error_details) { + $("#test_error").text(response.error_details); + } + $("#btn_post").removeClass("loading disabled"); } }); |