失败时的json返回

@param string|array $msg
@param int $status

@return JsonResponse
765016
public function fail($msg = 'Service Error', $status = 500)
    {
        if (is_string($msg)) {
            $messages = $this->standardMessage($msg);
        } else {
            $messages = $msg;
        }

        $reData = [
            'code'     => count($messages),
            'messages' => $messages,
        ];

        //打上Log
        Log::error('Service Error', $reData);

        return response()->json($reData, $status);
    }
1232550
protected function message($message, $statusCode) {
		$response =  $this->getAPIResponse(array(
			'message' => $message,
			'statusCode' => $statusCode
		));
		$response->setStatusCode($statusCode);
		return $response;
	}
1356209
public static function emailAdmin ($status, $msg)
	{
		
		// Check admin email constants are defined
		
		if (!defined ('EMAIL_FROM'))
		{
			status::Output ('ERROR', 'EMAIL_FROM not specified');
			return;
		}
		
		if (!defined ('AUTHOR_NAME'))
		{
			status::Output ('ERROR', 'AUTHOR_NAME not specified');
			return;
		}
		
		if (!defined ('AUTHOR_EMAIL'))
		{
			status::Output ('ERROR', 'AUTHOR_EMAIL not specified');
			return;
		}
		
		// Create email
		
		$email	= new Email;

		if (defined ('EMAIL_SMTP') && EMAIL_SMTP)
		{
			$email->setSMTPStream ();
		}
		else
		{
			$email->setPHPMail ();
		}
		
		// Set message
		
		$email->addHTML ("
			<p>CLI email from " . EMAIL_DOMAIN . ":<br />
			status: " . $status . "<br />
			message: " . nl2br ($msg) . "
			</p>
		");
		
		// Send to admin
		
		$email->addRecipient (AUTHOR_EMAIL, AUTHOR_NAME);

		if ($email->Send (EMAIL_FROM, 'CLI Message') && !\Sonic\Message::count ('error'))
		{
			return TRUE;
		}
		else
		{
			return FALSE;
		}
		
	}
1261440
public function stderr($msg, $status = self::STATUS_FAIL)
    {
        $msg = "<strong>".$msg."</strong>";
        $msg = $this->removeColors($msg);
        $msg = $this->replaceEOLs($msg);

        if (defined('STDERR')) {
            fwrite(STDERR, $msg);
        } else {
            echo $msg;
            if (count(\ob_get_status()) !== 0) {
                ob_flush();
            }
        }
        return $this;
    }
779352
public static function json($data, $status = NULL) {
        if ($status) {
            parent::setStatus($status);
        }
        parent::setContentType('application/json');
        return json_encode($data);
    }
1006
public static function responseJsonMerge($mdata = array(), $mergedData, $status = null, $msg = '', array $headers = array(), $options = 0)
    {
        $response = self::responseMerge($mdata, $mergedData, $status, $msg);
        return Response::json($response, $response['status'], $headers, $options);
    }
84913
protected function getErrorResponse($msg, $errorCode, $statusText, $headers = [])
    {
        return $this->setStatusText($this->statusTexts[$statusText])
                    ->setStatusCode($statusText)
                    ->setStatusMessage(self::ERROR_TEXT)
                    ->setErrorCode($errorCode)
                    ->setErrorMessage($msg)
                    ->respondWithErrorMessage($headers);
    }
1266635
protected function renderJSON($data = [], $status = 200, $flags = null)
    {
        $rendered = View::renderJSON($data, $flags);

        $this->response->getBody()->rewind();
        $this->response->getBody()->write($rendered);

        return $this->getResponse()
            ->withStatus($status)
            ->withHeader('Content-Type', 'application/json; charset=utf-8');
    }
1051428
private function getMessage($status) {
		if($this->messages === false) {
			$this->messages = require(__DIR__ . '/messages.php');
		}

		return isset($this->messages[$status]) ? $this->messages[$status] : "Error: $status";
	}
1011470
public static function response($mdata = array(), $status = null, $msg = '')
    {
        if (is_array($mdata) && isset($mdata['msg']) && isset($mdata['data']) && isset($mdata['status']) && !$status) {
            $status = $mdata['status'];
            $msg = $mdata['msg'];
            $mdata = $mdata['data'];
        }


        if (!$status && count($mdata)) {
            $status = 200;
        } elseif (!$status) {
            $status = 400;
        }


        $response = array(
            'status' => $status,
            'msg' => $msg,
            'data' => $mdata
        );

        return $response;
    }
1228182
public static function json($data = array(), $status = 200, array $headers = array(), $options = 0)
  {
    $etagMatch     = false;
    $headersToExpose = array();

    if (array_key_exists('ETag', $headers)) {
      $headersToExpose[] = 'ETag';

      // Empty the data if If-None-Match header match with ETag value
      $requestEtags = IlluminateRequest::getETags();

      if ( ! empty($requestEtags)) {
        foreach ($requestEtags as $etag) {
          if ($headers['ETag'] == $etag) {
            $etagMatch = true;
            $data    = array();

            break;
          }
        }
      }

      unset($requestEtags);
    }

    if (array_key_exists('Link', $headers)) {
      $headersToExpose[] = 'Link';
    }

    if (array_key_exists('X-Rate-Limit-Limit', $headers)) {
      $headersToExpose[] = 'X-Rate-Limit-Limit';
    }

    if (array_key_exists('X-Rate-Limit-Remaining', $headers)) {
      $headersToExpose[] = 'X-Rate-Limit-Remaining';
    }

    if (array_key_exists('X-Rate-Limit-Reset', $headers)) {
      $headersToExpose[] = 'X-Rate-Limit-Reset';
    }

    $headers['Access-Control-Expose-Headers'] = implode(', ', $headersToExpose);

    if ($etagMatch) {
      $response = parent::make('', 304, $headers);
    } else {
      $response = parent::json($data, $status, $headers);
    }

    $response->setCharset('utf-8');

    if (array_key_exists('ETag', $headers)) {
      $response->setCache(array(
        'etag' => $headers['ETag']
      ));
    }

    return $response;
  }
846991
public function getStatusMessage($status = null)
    {
        if (! $status) $status = $this->getStatus();

        if (! $status || ! isset($this->status_messages[$status])) throw new \LogicException("No such status. -> {$status}");

        return $this->status_messages[$status];
    }
526840
public function outputJson($data = null, $message = '', $status = 200)
    {
        // 错误信息返回格式可参考：[https://developer.github.com/v3/]
        if ($status != 200 && $message !== '') {
            $data = [
                'message' => $message
            ];
        }
        parent::outputJson($data, $status);
    }
17005
public static function get ($status = FALSE)
	{
		
		// If no status return all messages
		
		if ($status === FALSE)
		{
			return self::$messages;
		}
		
		// Return messages for a specific status
		
		if (isset (self::$messages[$status]))
		{
			return self::$messages[$status];
		}
		else
		{
			return array ();
		}
		
	}
243723
public function send($content = null, $status = null)
    {
        // Render json when content is array
        if (is_array($content)) {
            return $this->json($content)->send();
        } elseif (null !== $content) {
            $this->setContent($content);
        }

        if (null !== $status) {
            $this->setStatusCode($status);
        }

        // Trigger the after send callback
        $this->beforeSend && call_user_func($this->beforeSend, $this, $content);

        $this->sendHeader();
        $this->sendContent();

        // Trigger the after send callback
        $this->afterSend && call_user_func($this->afterSend, $this);

        return $this;
    }
291784
protected static function loadResult($status, $code, $message, $errors, $extras)
    {
        $Result = new static($status);

        if (! empty($code)) {
            $Result->setCode($code);
        }

        if (! empty($message)) {
            $Result->setMessage($message);
        }

        if (! empty($errors)) {
            $Result->setErrors($errors);
        }

        if (! empty($extras)) {
            $Result->setExtras($extras);
        }

        return $Result;
    }
626710
public function response($content, int $statusCode = 200, string $statusMessage = 'OK'): Response
    {
        $response = [
            'statusCode' => $statusCode,
            'statusMessage' => $statusMessage,
            'content' => $content,
        ];

        if ($this->config->application->debug->logRequest) {
            $this->log->addInfo('RESPONSE', $response);
        }

        // Create a response since it's an ajax
        //in order to use the current response instead of having to create a new object , this is needed for swoole servers
        $response = $this->response ?? new Response(); 
        $response->setStatusCode($statusCode, $statusMessage);
        $response->setContentType('application/vnd.api+json', 'UTF-8');
        $response->setJsonContent($content);

        return $response;
    }