public function exception(\Exception $ex)
    {
        /** If the current codec cannot encode JSON API, we need to reset it. */
        if ($this->getCodec()->willNotEncode()) {
            $this->codec = $this->api->getDefaultCodec();
        }

        return $this->getErrorResponse(
            $this->exceptions->parse($ex)
        );
    }