protected function formatFailure($result)
    {
        $appConfig = $this->di->get('config')['application'];
        $inflector = $this->di->get('inflector');

        $result->errors = [];

        //for each errorStore, build one or more error objects
        foreach ($this->errors as $error) {

            //if this error includes a list of validation issues, map them into error objects and concat the result
            if ($error->validationList) {
                $validationErrors = array_map(function (Message $validation) use ($error, $appConfig, $inflector) {
                    $field = $inflector->normalize($validation->getField(), $appConfig['propertyFormatTo']);
                    $details = [
                        'code' => $error->code,
                        'title' => $error->title,
                        'detail' => $validation->getMessage(),
                        'source' => ['pointer' => "/data/attributes/$field"],
                        'meta' => ['field' => $field]
                    ];
                    if ($appConfig['debugApp'] && $error->dev) {
                        $details['meta']['developer_message'] = $error->dev;
                    }
                    return $details;
                }, $error->validationList);

                $result->errors = array_merge($result->errors, $validationErrors);

                //however, if it's a plain error, concat an error object with some additional trace information
            } else {
                $details = [
                    'title' => $error->title,
                    'code' => $error->code,
                    'detail' => $error->more,
                ];

                //it doesn't make much sense to add stacktrace info to validation errors, right?
                if ($appConfig['debugApp']) {
                    $meta = array_filter([ //clears up empty keys
                        'developer_message' => $error->dev,
                        'file' => $error->file,
                        'line' => $error->line,
                        'stack' => $error->stack,
                        'context' => $error->context,
                    ]);

                    if ($meta) {
                        $details['meta'] = $meta;
                    }
                }

                $result->errors[] = $details;
            }
        }
    }
protected function formatFailure($result)
    {
        $appConfig = $this->di->get('config')['application'];
        $inflector = $this->di->get('inflector');

        $result->errors = [];

        //for each errorStore, build one or more error objects
        foreach ($this->errors as $error) {

            //if this error includes a list of validation issues, map them into error objects and concat the result
            if ($error->validationList) {
                $validationErrors = array_map(function (Message $validation) use ($error, $appConfig, $inflector) {
                    $field = $inflector->normalize($validation->getField(), $appConfig['propertyFormatTo']);
                    $details = [
                        'code' => $error->code,
                        'title' => $error->title,
                        'detail' => $validation->getMessage(),
                        'source' => ['pointer' => "/data/attributes/$field"],
                        'meta' => ['field' => $field]
                    ];
                    if ($appConfig['debugApp'] && $error->dev) {
                        $details['meta']['developer_message'] = $error->dev;
                    }
                    return $details;
                }, $error->validationList);

                $result->errors = array_merge($result->errors, $validationErrors);

                //however, if it's a plain error, concat an error object with some additional trace information
            } else {
                $details = [
                    'title' => $error->title,
                    'code' => $error->code,
                    'detail' => $error->more,
                ];

                //it doesn't make much sense to add stacktrace info to validation errors, right?
                if ($appConfig['debugApp']) {
                    $meta = array_filter([ //clears up empty keys
                        'developer_message' => $error->dev,
                        'file' => $error->file,
                        'line' => $error->line,
                        'stack' => $error->stack,
                        'context' => $error->context,
                    ]);

                    if ($meta) {
                        $details['meta'] = $meta;
                    }
                }

                $result->errors[] = $details;
            }
        }
    }
protected function formatFailure ( $ result ) { $ appConfig = $ this -> di -> get ( 'config' ) [ 'application' ] ; $ inflector = $ this -> di -> get ( 'inflector' ) ; $ result -> errors = [ ] ; //for each errorStore, build one or more error objects foreach ( $ this -> errors as $ error ) { //if this error includes a list of validation issues, map them into error objects and concat the result if ( $ error -> validationList ) { $ validationErrors = array_map ( function ( Message $ validation ) use ( $ error , $ appConfig , $ inflector ) { $ field = $ inflector -> normalize ( $ validation -> getField ( ) , $ appConfig [ 'propertyFormatTo' ] ) ; $ details = [ 'code' => $ error -> code , 'title' => $ error -> title , 'detail' => $ validation -> getMessage ( ) , 'source' => [ 'pointer' => "/data/attributes/$field" ] , 'meta' => [ 'field' => $ field ] ] ; if ( $ appConfig [ 'debugApp' ] && $ error -> dev ) { $ details [ 'meta' ] [ 'developer_message' ] = $ error -> dev ; } return $ details ; } , $ error -> validationList ) ; $ result -> errors = array_merge ( $ result -> errors , $ validationErrors ) ; //however, if it's a plain error, concat an error object with some additional trace information } else { $ details = [ 'title' => $ error -> title , 'code' => $ error -> code , 'detail' => $ error -> more , ] ; //it doesn't make much sense to add stacktrace info to validation errors, right? if ( $ appConfig [ 'debugApp' ] ) { $ meta = array_filter ( [ //clears up empty keys 'developer_message' => $ error -> dev , 'file' => $ error -> file , 'line' => $ error -> line , 'stack' => $ error -> stack , 'context' => $ error -> context , ] ) ; if ( $ meta ) { $ details [ 'meta' ] = $ meta ; } } $ result -> errors [ ] = $ details ; } } }
darn there was an error, process the offending code and return to the client

@param $result
darn there was an error process the offending code and return to the client