// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "config.h"
#include "modules/push_messaging/PushError.h"

#include "core/dom/ExceptionCode.h"
#include "wtf/OwnPtr.h"

namespace blink {

PassRefPtrWillBeRawPtr<DOMException> PushError::take(ScriptPromiseResolver*, WebType* webErrorRaw)
{
    OwnPtr<WebType> webError = adoptPtr(webErrorRaw);
    switch (webError->errorType) {
    case WebPushError::ErrorTypeAbort:
        return DOMException::create(AbortError, webError->message);
    case WebPushError::ErrorTypeNetwork:
        return DOMException::create(NetworkError, webError->message);
    case WebPushError::ErrorTypeNotFound:
        return DOMException::create(NotFoundError, webError->message);
    case WebPushError::ErrorTypeUnknown:
        return DOMException::create(UnknownError);
    }
    ASSERT_NOT_REACHED();
    return DOMException::create(UnknownError);
}

void PushError::dispose(WebType* webErrorRaw)
{
    delete webErrorRaw;
}

} // namespace blink

// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "config.h"
#include "modules/push_messaging/PushError.h"

#include "core/dom/ExceptionCode.h"
#include "wtf/OwnPtr.h"

namespace blink {

PassRefPtrWillBeRawPtr<DOMException> PushError::take(ScriptPromiseResolver*, WebType* webErrorRaw)
{
    OwnPtr<WebType> webError = adoptPtr(webErrorRaw);
    switch (webError->errorType) {
    case WebPushError::ErrorTypeAbort:
        return DOMException::create(AbortError, webError->message);
    case WebPushError::ErrorTypeNetwork:
        return DOMException::create(NetworkError, webError->message);
    case WebPushError::ErrorTypeNotFound:
        return DOMException::create(NotFoundError, webError->message);
    case WebPushError::ErrorTypeUnknown:
        return DOMException::create(UnknownError, webError->message);
    }
    ASSERT_NOT_REACHED();
    return DOMException::create(UnknownError);
}

void PushError::dispose(WebType* webErrorRaw)
{
    delete webErrorRaw;
}

} // namespace blink

Use provided message for UnknownError.
[Push] Use provided message for UnknownError.

BUG=None

Review URL: https://codereview.chromium.org/809493002

git-svn-id: bf5cd6ccde378db821296732a091cfbcf5285fbd@187240 bbb929c8-8fbe-4397-9dbb-9b2b20218538
