向用户显示更详细的错误消息 -- 8 领域 drupal 相关 的问题

Showing more detailed error messages to user


0
vote

问题

中文

我用连接到Drupal后端的钛制作一个应用程序。即时使用令人敬畏的库( https://github.com/jebeuckm/drupal-client ) 。

如何显示更详细的错误消息(例如,已删除电子邮件/用户名)?

当我注册已经注册的新用户时,我只在iOS中获得406个错误代码。

  error: {"success":false,"code":406,"source":{"url":"http://domain/user/register.json","method":"POST","ondatastream":null},"type":"error","error":"HTTP error"}   

我注意到,当我与Android连接时,有更多的详细信息可用(例如,例如,例如)。

任何想法?

更新:

在Android中,我收到我需要的信息(Statustext)。为什么我不能在ios中访问它?

  error: {"code":-1,"source":{"autoRedirect":true,"status":406,"allResponseHeaders":"Date:Mon, 13 Jul 2015 10:09:47 GMT Server:Apache/2.2.15 (Red Hat) Expires:Sun, 19 Nov 1978 05:00:00 GMT Cache-Control:no-cache, must-revalidate, post-check=0, pre-check=0 Content-Length:259 Content-Type:application/json Keep-Alive:timeout=15, max=100 Connection:Keep-Alive ","connected":false,"password":null,"validatesSecureCertificate":false,"tlsVersion":0,"responseText":"{"form_errors":{"name":"The name <em class=\"placeholder\">editor83</em> is already taken.","mail":"The e-mail address <em class=\"placeholder\">editor83@vodes.net</em> is already registered. <a href=\"/user/password\">Have you forgotten your password?</a>"}}","username":null,"responseXML":null,"statusText":"Not Acceptable : The name editor83 is already taken. The e-mail address editor83@vodes.net is already registered. Have you forgotten your password?","apiName":"Ti.Network.HTTPClient","location":"http://editors-testdrupal.rhcloud.com/rest/v1/user/register.json","readyState":3,"domain":null,"responseData":{"height":0,"bubbleParent":true,"type":2,"mimeType":"application/json","apiName":"Ti.Blob","nativePath":null,"file":null,"text":null,"length":259,"width":0},"connectionType":"POST","autoEncodeUrl":true,"bubbleParent":true,"_events":{"disposehandle":{}}},"error":"Not Acceptable : The name editor83 is already taken. The e-mail address editor83@vodes.net is already registered. Have you forgotten your password?","success":false} [INFO] :   ALERT: (KrollRuntimeThread) [47,17536] Not Acceptable : The name editor83 is already taken. The e-mail address editor83@vodes.net is already registered. Have you forgotten your password? [INFO] :   [object Object]account was not created   

更新2:

似乎更像是一个噬菌体/ android / iOS问题,因此我在主论坛上发布了这个问题。

https://stackoverflow.com/questions/31381522/drifferent -test-object-opport-indroid-and-ios

如果我在这里得到一个答案的答案。

英文原文

im making an app with titanium that connects to a drupal backend. im using the awesome library (https://github.com/jbeuckm/drupal-client).

how can i show more detailed error messages (e.g. email/username has already been taken)?

i only get a 406 error code in ios when i register a new user that has already been registered.

error: {"success":false,"code":406,"source":{"url":"http://domain/user/register.json","method":"POST","ondatastream":null},"type":"error","error":"HTTP error"} 

i noticed that when i connect with android there are more detailed messages available (e.source.statusText for instance).

any ideas?

update:

in android i get the information that i would need (statusText). why cant i access it in ios?

error: {"code":-1,"source":{"autoRedirect":true,"status":406,"allResponseHeaders":"Date:Mon, 13 Jul 2015 10:09:47 GMT\nServer:Apache/2.2.15 (Red Hat)\nExpires:Sun, 19 Nov 1978 05:00:00 GMT\nCache-Control:no-cache, must-revalidate, post-check=0, pre-check=0\nContent-Length:259\nContent-Type:application/json\nKeep-Alive:timeout=15, max=100\nConnection:Keep-Alive\n","connected":false,"password":null,"validatesSecureCertificate":false,"tlsVersion":0,"responseText":"{\"form_errors\":{\"name\":\"The name <em class=\\\"placeholder\\\">editor83</em> is already taken.\",\"mail\":\"The e-mail address <em class=\\\"placeholder\\\">editor83@vodes.net</em> is already registered. <a href=\\\"/user/password\\\">Have you forgotten your password?</a>\"}}","username":null,"responseXML":null,"statusText":"Not Acceptable : The name editor83 is already taken. The e-mail address editor83@vodes.net is already registered. Have you forgotten your password?","apiName":"Ti.Network.HTTPClient","location":"http://editors-testdrupal.rhcloud.com/rest/v1/user/register.json","readyState":3,"domain":null,"responseData":{"height":0,"bubbleParent":true,"type":2,"mimeType":"application/json","apiName":"Ti.Blob","nativePath":null,"file":null,"text":null,"length":259,"width":0},"connectionType":"POST","autoEncodeUrl":true,"bubbleParent":true,"_events":{"disposehandle":{}}},"error":"Not Acceptable : The name editor83 is already taken. The e-mail address editor83@vodes.net is already registered. Have you forgotten your password?","success":false} [INFO] :   ALERT: (KrollRuntimeThread) [47,17536] Not Acceptable : The name editor83 is already taken. The e-mail address editor83@vodes.net is already registered. Have you forgotten your password? [INFO] :   [object Object]account was not created 

update 2:

it seems to be more of a ecplise/android/ios issue, so ive posted the question on the main forum.

https://stackoverflow.com/questions/31381522/different-rest-object-output-in-android-and-ios

if i get an answer ill post it here as well.

  

回答列表

0
 
vote

您可能希望检查 services.alter.api.php

如这个帖子

  <?php /**  * Allows alteration of error data before the status code or message are returned.  *  * @param array $error_alter_array  *   An associative array with the following keys:  *     - 'code': the HTTP status code.  *     - 'header_message': the message returned as part of the error response  *       (for instance, "404 Not found").  *     - 'body_data': data that was passed to the thrown exception.  * @param array $controller  *   The current controller definition.  * @param array $arguments  *   Arguments passed to the current controller.  *  * @see RESTServer->handleException() */ function hook_rest_server_execute_errors_alter(&$error_alter_array, $controller, $arguments) {  }   
 

You might want to check services.alter.api.php

As described in this post

<?php /**  * Allows alteration of error data before the status code or message are returned.  *  * @param array $error_alter_array  *   An associative array with the following keys:  *     - 'code': the HTTP status code.  *     - 'header_message': the message returned as part of the error response  *       (for instance, "404 Not found").  *     - 'body_data': data that was passed to the thrown exception.  * @param array $controller  *   The current controller definition.  * @param array $arguments  *   Arguments passed to the current controller.  *  * @see RESTServer->handleException() */ function hook_rest_server_execute_errors_alter(&$error_alter_array, $controller, $arguments) {  } 
 
 
 
 
0
 
vote

派对迟到了,但从沙盒模块的项目页面休息错误消息< / a>:

服务模块返回JSON格式错误的服务模块 消息而不是仅通过HTTP具有错误信息的WSOD 标题。在许多情况下,应用程序需要这一点 要求妥善反应。同时它输出人类 可读的输出,暗示开发人员直接发生了什么 浏览器。

用法: 使用该功能设置的任何代码和消息 Services_Error($邮件,$ CODE = 0,$ DATA = NULL)由服务提供 模块或在自定义[您的服务]中.Service.inc文件被尊重。 这样,您可以为服务提供API特定错误数据。

 

Coming a bit late to the party but from project page of the sandbox module REST Error Message:

Extension for the Services module returning a JSON formatted error message instead of a WSOD with error info only through the HTTP header. In many cases this is needed by the application making the request to react appropriate. At the same time it outputs human readable output, hinting developers directly what is going on in the browser.

Usage: Any code and message set with the function services_error($message, $code = 0, $data = NULL) by the Services module or in a custom [YOUR-SERVICE].service.inc file is respected. That way you can provide API specific error data for your service.

 
 

相关问题

3  我应该在哪里存储第三方外部JS库?  ( Where should i store 3rd party external js libraries ) 
这是一个跟进在drupal 8中定义JavaScript库> 我有一个第三方库,我不想用模块捆绑。在Drupal 7中,我可以询问用户提取到 sites/all/libraries 是什么是Drupal 8中的最佳实践? ...

2  如何使用选项封装Drush命令来使用参数  ( How can i encapsulate drush command with option to use arguments ) 
我有一个drush命令,用于在其中安装drupal网站。我不想一直在所有的配置中键入此命令,因为它很长,所以我想将命令封装为别名,但我仍然希望将其他参数传递给原始命令。 特别是我需要至少传递DB URL,因为它们始终会不同。 我在想这样的事情: drush install-mysite --db-url="..." ...

1  来自UI的Drupal 8自定义实体?  ( Drupal 8 custom entities from a ui ) 
是否有人知道从Drupal 8 UI创建自定义实体,这些UI不是eck的?我用eck和仍然有点越野车试试。 ...

-2  如何为设计者进行用户注册制作模板?  ( How make a template for designer for user registration ) 
我正在寻找一个"用户 - regiser-form.html.twig" ,用于使用枝条的页面中字段的自定义位置。 这就是设计师所希望的: <div class="row"> <div class="col-md-6"> {{ form.field_name }} </div> <div...

2  使用没有Base64的Drupal Services模块的发布/上传文件(使用REST MultiPart / Form-Data)[已关闭]  ( Post upload file using drupal services module without base64 using rest multipa ) 
关闭。这个问题需要更多聚焦。它目前不接受答案。 想要改进这个问题?更新问题,因此它仅介绍了编辑此帖子。 关闭 3年前。 ...

1  为什么在发布节点时丢失标题丢失?  ( Why are the titles are lost for translations when posting nodes ) 
我目前在drupal 8中调用一个项目。我正在将HAL JSON与相关标头发布到/实体/节点以创建节点。我在这个例子中包括翻译: { "_链接" :{"类型" :{"href" :" https:// localtest / str /类型/ node / page "}}, "title" :[{"value" ...

2  如何防止安装从UI运行?  ( How to prevent installation to run from ui ) 
我有一个安装配置文件,它将纯粹通过Drush / CLI安装。所以我需要防止任何人从Web界面运行安装。 是什么最好的方法? ...

2  如何在开发期间停止javascript缓存?  ( How can i stop javascript from being cached during development ) 
我有一个drupal 8.00-beta11站点,我试图动态地将js添加到一个页面,以便每次编辑js文件时都没有清除缓存。我有一个自定义模块(允许调用它my_module)在drupal_root / modules中。我的javascript文件是drupal_root / modules / my_module ...

2  使用字段设置控制节点的内容  ( Controlling nodes content using field setting ) 
在我正在开发的模块中,我希望根据用户的选择来控制节点内容中的链接的显示。我想向用户展示此选项(他是否想要在特定节点上显示链接),当他在这样 /node/{node}/edit 的路径上时,在该页面上可用其他选项(菜单设置,注释设置) 。在进行一些研究时,我设法发现将需要使用现场插件。这我说是因为评论模块实现 Fiel...

3  无法执行DRUSH命令  ( Not able to execute drush commands ) 
我正在尝试在虚拟机(Ubuntu)上设置Drupal 8环境,当我尝试清除缓存时,我收到了错误: drupal8@drupal8-VirtualBox:/var/www/drupal-8.0-alpha5$ drush cc all Command cache-clear needs a higher boots...

0  如何使视图模式仅适用于所选捆绑?  ( How to make view mode available only to selected bundle ) 
我有三个分类词汇表意味着我有三个词汇实体类型。我有几种视图模式,其中一个只能可用于其中一个词汇表。 负责获取可用视图模式的方法是 DrupalCoreEntityEntityManager::getAllDisplayModesByEntityType() ,但它在捆绑包之间并不不同,只有实体类型。 有没有办法,我可...

13  如何在403错误之后将匿名用户重定向到登录表单?  ( How to redirect an anonymous user to the login form after a 403 error ) 
如果这样的用户遇到403错误,我想将匿名用户重定向到登录表单。 我已经创建了事件订阅者,这是我的代码,但我最终在当前页面上循环。 /** * Redirect anonymous user to login page if he encounters 404 or 403 * response. ...

0  节点内容慢慢AjaxResponse  ( Slow ajaxresponse for node content ) 
我正在使用drupal 8所以有很少的文档或基准测试,但我相信我已经为ajax响应设置的路线并不像它可能的表现。 这是路线: next_node.ajax: path: '/node/{node}' defaults: _controller: 'Drupal ext_nodeController...

1  这是完整内容和默认模式之间的区别?  ( Which is the difference between the full content and the default mode ) 
fieldui使用 default 作为实体表单/视图显示的默认值。但EntityViewBuilderInterface使用完整作为默认值。 也是template_preprocess_taxonomy_term()使用 full 值来了解当前页面是分类项。 那么我应该在哪一个知道是否正在使用"默认" 模式?我应...

1  如何设置包含按日期订购的事件列表的视图  ( How to set up a view containing a list of events ordered by date ) 
我希望在前端上有一个事件列表: Upcoming (Newest on top) <Event1 title> @ <Event 1 Date> <Event2 title> @ <Event 2 Date> . . Past (in reversed order) <Event3 title> @ <Event...

2  Drupal8视图破损的处理程序与自定义实体类型  ( Drupal8 views broken handler with custom entity type ) 
我正在建立一个 bet网站长期测试Drupal 8。 感谢Drupal Console,我设法创建了许多自定义实体类型。 现在我想公开我的实体观点,但我收到这条消息; 我唯一从我的游戏实体类型完成的定制之一是更改表名:从 game 到 mespronos_game ,通过编辑来自:的注释 base_tab...

0  无法在自定义模块中向数据库提交表单  ( Unable to submit form to database in custom module ) 
我正在构建一个自定义模块,我无法使用该表单与数据库交谈。上传到文件系统的部分工作正常。 这是mymoduleblock.php <?php namespace Drupalmy_modulePluginBlock; use DrupalCoreBlockBlockBase; use DrupalCoreFo...

1  如何自定义与枝条的形式  ( How custom a form with twig ) 
我以编程方式制作形式,我正在寻找网络设计师如何更改渲染。 public function buildForm(array $form, FormStateInterface $form_state) { $form['metier'] = array( '#type' => 'sear...

2  如何将JavaScript库添加到字段格式化程序?  ( How do i add a javascript library to a field formatter ) 
我正在尝试包含一个javascript画廊( jquery lightgallery ) Drupal 8站点并为此目的写了一个字段格式化器。 现在我需要使用此字段格式化程序将jQuery LightGallery添加到页面上,并在页面准备就绪时调用库。但是,我对我应该如何做到这一点。 我在包含我的字段格式化器中...

7  休息403个错误  ( Getting a 403 error in rest ) 
所以我一试着休息。在VM中安装Drupal-8.0.0-beta12。卷曲使用 curl http://testing.dev/drupal8/node/1?_format=json ,但我不确定为什么要使用dev http客户端获得 403 错误消息: 任何想法? ...




© 2021 it.wenda123.org All Rights Reserved. 问答之家 版权所有


Licensed under cc by-sa 3.0 with attribution required.