wakeonweb/errors-extra-library 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

wakeonweb/errors-extra-library

Composer 安装命令:

composer require wakeonweb/errors-extra-library

包简介

Wakeonweb errors extra library

README 文档

README

  • Error dictionary

Installation

composer.json

    "require": {
        "wakeonweb/errors-extra-library": "~1.0"
    }

AppKernel

$bundles[] = new WakeOnWeb\ErrorsExtraLibrary\App\Bundle\WakeonwebErrorsExtraLibraryBundle();

Configuration

Override http status code, show error messages on exceptions:

wakeonweb_errors_extra_library:
    force_format: json
    exception:
        http_status_codes:
            Pagerfanta\Exception\OutOfRangeCurrentPageException: 400
        show_messages:
            - Pagerfanta\Exception\OutOfRangeCurrentPageException
        log_levels:
            Pagerfanta\Exception\OutOfRangeCurrentPageException: notice
            Pagerfanta\Exception\NotValidCurrentPageException: error

Log level values as defined by PSR-3 (from RFC 5424).

Exception listener

The bundle adds an exception listener to format the response when the requested response format is application/json.

Default JSON response

  • code : HTTP status code
  • message : HTTP reason phrase

Example

{
    "code": 403,
    "message": "Forbidden",
}

Form Errors normalization

This bundle also standardize Symfony Form Errors.

With something like this:

    if (!$form->isValid()) {
        return new JsonResponse($this->normalizer->normalize($form, 'json'), 400);
    }

You will have:

{  
   "code":"400",
   "message":"Validation Failed",
   "errors":{  
      "children":{  
         "firstName":{  
            "errors":[  
               [  
                  "This value is too short. It should have {{ limit }} character or more.|This value is too short. It should have {{ limit }} characters or more.",
                  {  
                     "{{ value }}":"\"LL\"",
                     "{{ limit }}":3
                  }
               ]
            ]
         },
         "lastName":{  
            "errors":[  
               [  
                  "This value should not be blank.",
                  {  
                     "{{ value }}":"null"
                  }
               ]
            ]
         }
      },
      "errors":[  
         [  
            "This is a global form error with {{ param }}",
            {  
               "{{ param }}":"TEST"
            }
         ]
      ]
   }
}

统计信息

  • 总下载量: 171
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2019-02-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固